Open Pike opened 12 years ago
I see two big problems with XPath:
element[1]
).OTOH, it's an established technology whose purpose is exactly what we want.
As far as CSS goes:
element:nth-child(1)
There's one big drawback to CSS regarding the syntax: it doesn't let you explicitly select children, as opposed to all descendants.
In XPath, you can do:
element
(short for ./element
) which means all element
children of the context node,//element
which means all element
descendants of the context node.In CSS (or, more specifically, the Selectors API), you can only do:
element
which means all element
descendants of the context node.There is nothing like > element
, because there is no way to reference the context node itself (which in XPath can be achieved by typing a single dot .
).
This seems to be a pretty big limitation, especially when we assume that most of the uses of l10n-path will be very simple ones, targeting immediate children of the context node. Having a way to reference immediate children would be a plus.
The way Sizzle (and jQuery) solve this is to add a temporary ID on the context node and then run the query from its parent:
https://github.com/jquery/sizzle/blob/master/sizzle.js#L1202-1233
I’d suggest keeping XPath (l10n-path) and implementing CSS selectors along (l10n-select). L20n could be very interesting in a document engineering approach, where people are very familiar with XML workflows.
We shouldn't use xpath to reference nodes, only evil specs do that. Let's go for CSS selectors instead.