XML technologies / XPath / XPath 2.0: language reference / Path expressions: axes / Ancestor axis
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 4.)
Defined for: XPath 1.0 and 2.0 (not in XQuery 1.0)
Direction: reverse
Axis identifier: ancestor
Abbreviated syntax: none
Figure: the ancestor axis.
The ancestor axis contains all direct and indirect ancestors of the context node, from its parent up to and including the document node. Apart from the document node, it contains only elements: a node must have children to belong to this axis.
Example:
ancestor::mein_element
tests all ancestors of the current node and selects element nodes namedmein_element. The document node has no name and cannot be selected. The result is in reverse document order.
ancestor::*
selects all elements on the context node’s ancestor axis, excluding the document node. For the root element, the result is therefore empty: although its parent is the document node, the wildcard test using*does not select that node.
ancestor::node()
selects all nodes on the ancestor axis: its element nodes and the document node.
ancestor::text()
This expression tests whether any ancestors of the current node are text nodes. It is syntactically valid but meaningless here, since this axis can contain only element nodes. The result sequence is therefore empty.
Copyright © Galileo Press, Bonn 2008
You may print the online version for private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn