[jQuery] Translating XPath expressions to CSS selectors

2008-02-07 Thread tim

 The CSS 3 :root selector is not supported unfortunately, but the root
 node of a document is represented by document.documentElement.

 So you could try:

 $(' KNOWN_NODE', document.documentElement)

 or

 $(document.documentElement.tagName + '  KNOWN_NODE')

 Does that work?

Yes it does, thanks!  This clears up a lot of confusion on my part even
though it isn't the answer I was looking for.  This will only work when
KNOWN_NODE is only one level deep, and as far as I know there is still no
way to go n levels deep with CSS expressions.

However, I now realise I can do this with the children() method:

$(document.documentElement).children().find(' KNOWN_NODE')

Lemme see if I can hack that into the Basic XPath plugin...

Thanks,

Tim



[jQuery] Translating XPath expressions to CSS selectors

2008-02-06 Thread tim

Hi,

I'm trying to migrate from jQuery 1.1.3 to 1.2.2, and I'm having trouble
converting my XPath expressions.  In CSS, asterisks are deep, i.e. they
match all elements that are descendants of the context node.  In XPath,
they are not, i.e. they match only the elements that are _direct_
descendants of the context node.

Consider this XML:

unknown_node_name
  KNOWN_NODEright node/KNOWN_NODE
  more_unknown_deepiness
KNOWN_NODEwrong node/KNOWN_NODE
  /more_unknown_deepiness
/unknown_node_name

Now, to get the right node, I would use the XPath expression
/*/KNOWN_NODE.  (Note that the node name has to be uppercase for some
reason, or jQuery 1.1.3 won't find anything at all.)

I don't see any way to do this with CSS selectors.  The Basic XPath plugin
translates the XPath expression to *  KNOWN_NODE, which returns both
the right node _and_ the wrong node.

Anyone have a clue as to what I should do?

Tim