zbraniecki / l20n

Python l20n support library
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

move from xpath to css selectors for refs #2

Open Pike opened 12 years ago

Pike commented 12 years ago

We shouldn't use xpath to reference nodes, only evil specs do that. Let's go for CSS selectors instead.

stasm commented 12 years ago

I see two big problems with XPath:

OTOH, it's an established technology whose purpose is exactly what we want.

As far as CSS goes:

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:

In CSS (or, more specifically, the Selectors API), you can only do:

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

fabi1cazenave commented 12 years ago

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.