Saturday, 15 June 2013

xml - How to use XPath to find the closest ancestor in a ancestor-or-self nodelist -


I have a structure with such recursive elements:

  & lt; A & gt; & Lt; P & gt; & Lt; A & gt; & Lt; / A & gt; & Lt; / P & gt; & Lt; A & gt; & Lt; P & gt; & Lt; A & gt; & Lt; C att = "val" /> & Lt; / A & gt; & Lt; / P & gt; & Lt; / A & gt; & Lt; / A & gt;   

If you are in the form of a C-node, there is $ currentNode, when I use Express

     

I get an anonymous list of nodes that match the expression What I need to always get the node to be closest to the tree, in the branches the deepest or highest level.

Unfortunately, I could not use XPath 2 max function:

     

Note that the closest node is not always above the reference, just above the top ...

Any suggestions appreciated!

I think you ordered the nodes Get to the former from the parent. Try the $ currentNode / ancestor-or-self :: a [1] to get the parent of c att = "val".

No comments:

Post a Comment