What is Ancestor Axis : ancestor « XPath « XML Tutorial






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.








4.5.ancestor
4.5.1.What is Ancestor Axis
4.5.2.select ancestor::*
4.5.3.select="ancestor::names/child::name[1]/child::family"
4.5.4.Is product the ancestor of 'Java'?
4.5.5.for-each select="ancestor::*"