Re: nth descendent selector

On Tue, 2012-11-13 at 11:27 -0800, Tab Atkins Jr. wrote:
> On Fri, Nov 9, 2012 at 2:33 AM, Dave Smith <da__smith@hotmail.com> wrote:
> > For example
> > li:nth(7)
> > would be equivalent to document.getElementsByTagName('li')[6]
> 
> The XQuery language (cousin to Selectors) has this functionality.
(as does XPath)

> Unfortunately, it's difficult to do in Selectors, because all browsers
> (and most JS-based selector engines, too) optimize selectors by
> evaluating them right-to-left, rather than the left-to-right that you
> probably expect.

For what it's worth, XQuery engines do this too - or sometimes evaluate
from the middle, too - for performance reasons.

There were papers on this at various VLDB conferences.

Early on in XQuery develpment there were concerns about performance of
the XPath "full axis feature", but it turned out that the workarounds
users found for missing axis support were massively slower and harder to
optimize than native support; the same is probably true of some of the
CSS selector proposals. It also turned out that the "full axis feature"
could be optimized heavily - e.g., again, there was a paper I think at
VLDB, showing how to turn backwards-looking expressions into
forwards-looking ones, so that you could implement preceding-sibling and
friends as efficiently as following-sibilng even in a streaming
environment.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
The barefoot typographer - http://www.holoweb.net/~liam/

Received on Tuesday, 13 November 2012 21:57:32 UTC