W3C home > Mailing lists > Public > www-style@w3.org > April 2005

Re: XPath & CSS, again

From: Bert Bos <bert@w3.org>
Date: Mon, 11 Apr 2005 23:36:37 +0200
To: Pascal Schmitt <pascal@cebra.nu>
Cc: www-style@w3.org
Message-ID: <20050411213636.GA12123@Candy.local>

On Mon, Apr 11, 2005 at 07:49:09PM +0000, Pascal Schmitt wrote:
> Hello!
> >I think XPath has different goals, viz., selecting not just elements,
> >but also individual attributes, comments, etc. And it is meant to be
> >used by a different group of people. That is why it has a different
> >syntax. Note that not only does it lack special syntax for CLASS
> >attributes, it *can't* select on CLASS attributes at all. (With XSLT,
> >my estimate is that you need about 50 lines to select an element with a
> >certain CLASS. With the new regular expressions in XPath 2.0 it is
> >tricky, but possible within XPath.) Clearly that is not what XPath was
> >designed for.
> Really? I thought it would be enough to use this expression:
> //*[(@class = $c) or contains(@class, concat(' ', $c, ' ')) or 
> starts-with(@class, concat($c, ' ') or ends-with(@class, concat(' ', 
> $c)]

Yes, that's a start. There are indeed four cases to distinguish, but
that it not all. In HTML, the value is case-insensitive, and in other
languages (SVG and MathML, e.g.) the space is not necessarily a space,
but may be any white-space character. (CSS doesn't care what the type
of the attribute is. In HTML it happens to be NMTOKENS, in SVG/MathML
it is CDATA.)

There is also the minor issue that the class attribute is not
necessarily called "class." But usually you know what format you write
a style sheet for, so you also know what attribute you are matching
on. And so far all W3C formats that have a class attribute have called
it "class."

> (okay, it /is/ long, but not 50 lines. )

Converting to lowercase has no built-in function in XPath (1.0). You
can do it in XSLT with a few variables and a couple of lines of code.

> My intention was not to /replace/ CSS with XPath but to enhance it. 
> Especially for generated-content, this would be helpful as there is 
> afaik no special CSS-Syntax yet (and you could use XPath 1:1 for 
> generated-content, couldn't you?)

You'll have to explain that...

The CSS selectors for generated content are :after and :before (and
::marker in CSS3 for the list marker).

CSS can select generated content, because there is only a handful of
things that *can* be generated.

How would XPath select generated content? Generated content, by
definition, is not in the document. It is not any of the node types
that XPath has expressions for. It only exists *after* the style sheet
has been applied.

  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Monday, 11 April 2005 21:36:42 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:17 UTC