W3C home > Mailing lists > Public > www-style@w3.org > March 2000

xpath and selectors

From: Joe Hewitt <joe@joehewitt.com>
Date: Sun, 12 Mar 2000 01:03:27 -0500
To: <www-style@w3c.org>
Message-ID: <NDBBJPCODLDHLAGMEIADAEIHCDAA.joe@joehewitt.com>
It occurred to me today as I was perusing the CSS3 selectors draft that much
of what one can do with CSS selectors is the same thing that one would do
with an XPath expression.  Would it not make sense for both CSS and XSL to
use the same language for selecting nodes?

The only thing I can think of that XPath can't do that CSS selectors do is
pseudo-elements/classes.   Some things like :first-line, :hover, :active,
:focus, etc... can't be accomplished with XPath because they refer to a sort
of "meta" state. However, things like :before, :first-child, :nth-child()
would be easily accomplished.  Perhaps some syntax for "meta-states" could
be added to the XPath spec using the single colon as the operator.

Some example syntaxes might look like this:

//p[@id=p1] {...}  ( p#p1 {...} )

//a:hover {...} ( a:hover {...} )

//div[@class=blue] {...} ( .blue {...} )

I realize that XPaths are a little bit more complex than CSS selectors, and
will often look a bit ugly in comparison (as seen in comparisons above).
But the advantage of course would be the added power and flexibility of
XPath, and the simplicity of only having to develop one language for
applying XSL/CSS styles to an XML document.

For backwards compatibility, perhaps a property can be added to the XHTML
style element called "selectors" which could take a value of "xpath" or
"css" to specify which language should be used. Of course it would default
to "css" for now.

I'm sure that I'm not the first person to think of this.  Has there been any
dialogue in the past on the subject of unifying the style node selection
languages?

- Joe
Received on Sunday, 12 March 2000 01:03:58 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:04 GMT