Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to traverse back to the parent node in the XML file by using Xpath(using XSLT) query?

Let us have a xml tree of depth N. I have traveresd the last node means i am at last note. Now i wanted to go back to some level up (say at N-3) in the xml tree from that last node.

Please let me know the syntax for the XPATH query so that i can reached at intended node in the xml tree.

like image 290
Santosh kumar Avatar asked Sep 09 '10 11:09

Santosh kumar


People also ask

How do I traverse back to parent in XPath?

Hey Hemant, we can use the double dot (“..”) to access the parent of any node using the XPath. For example – The locator //span[@id=”first”]/.. will return the parent of the span element matching id value as 'first.

What does XPath use to traverse the XML tree?

XPath uses path expressions to select nodes or node-sets in an XML document.


1 Answers

Use:

ancestor::node()[3] 

or

../../.. 
like image 90
Dimitre Novatchev Avatar answered Oct 07 '22 17:10

Dimitre Novatchev