Mega Code Archive

 
Categories / XML Tutorial / Xpath
 

What is Ancestor Axis

The ancestor axis selects the parent node of the context node, the parent of that node, its parent, and so  on until the root node of the document is selected.  If the context node is the root node, the ancestor axis returns an empty node-set.  If you had an XML document such as  <Book>      <Chapter number="1">         <Section>This is the first section.</Section>         <Section>This is the second section.</Section>     </Chapter>     <Chapter number="2">         content     </Chapter> </Book> and the context node were the second Sectionelement node in Chapter 1, then the location path  ancestor::*  would return the Chapter element node, which has a number attribute node with a value of 1, the Book element node, and the root node.