Kroc/DOMTemplate

Port css2xpath.js

Opened this issue · 6 comments

Kroc commented

The plan is to support full CSS queries for queries as these are better known, easier for web developers to use and more natural to the content being worked with.

There's a compact JavaScript CSS to XPath converter here https://code.google.com/p/css2xpath/source/browse/trunk/src/css2xpath.js that I can port to PHP.

Kroc commented

One consideration that came to me last night was that if using CSS to select, there needs to be a way to select element attributes (something CSS can't intrinsically do), and that there would be a need to select and element based on it's attributes, but also select an attribute of that element. Will give this my consideration when I get to it.

Eh? CSS has attribute selectors. I'm probably misunderstanding you.

Kroc commented

Yes, CSS has attribute selectors to select an element based upon an attribute, but it cannot select the attribute itself! You can't target the href in a href! :)

Oh, right.

You don't really need to target an attribute do you? Once you've got the node you can just use getAttribute or setAttribute to work on it.

Kroc commented

Well, there's a need to do it in the CSS for the instance of automatically running a large number of 3rd-party queries through DOMTemplate -- i.e. the translation run in NNF. The translations are provided as a simple array of 'query' > 'string' and have the need to set attributes. The translation logic in NNF simply passes the whole array to DOMTemplate, it doesn't check which points to an attribute and which doesn't; and that would be a bad idea anyway as it would mean running the queries twice, or worse re-implementing parts of DOMTemplate within an NNF function.

IMO I should change the CSS attribute selector (without condition), i.e. e[attrib] to target the attribute itself. There shouldn't be much need to select an element only by the presence of an attribute; the dev can use the heirarchy or a class/ID. Alternatively I could add an @attrib extension to the CSS.