XML technologies / XPath / XPath 2.0: language reference / Path expressions: axes / Descendant-or-self axis
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 4.)
Defined for: XPath 1.0 and 2.0, XQuery 1.0
Direction: forward
Axis identifier: descendant-or-self
Abbreviated syntax: //
Figure: the descendant-or-self axis.
The descendant-or-self axis contains the context node and all its direct and indirect descendants. It is the union of the descendant and self axes.
For a document context node, this axis contains the entire document tree.
The descendant-or-self axis also has the abbreviated double-slash syntax “//”. Unlike a single slash, this abbreviation cannot be used without a following node test.
Example:
descendant-or-self::*
selects the current node and all element nodes descended from it. If the current node is the document node, that node and every element are selected. If the current node is not an element, the result sequence is empty.
descendant-or-self::node()
selects the current node and all its descendants, regardless of kind, but excludes attribute and namespace nodes of both the current node and its descendants. For a document context node, the whole document tree is selected.
//*
As a simple path expression, the double slash starts at the document node. It selects all element nodes in the document tree and the document node itself.
Caution: the abbreviation alone is not context-sensitive
Used alone, this syntax, unlike the first example’s expression descendant-or-self::*, is not context-sensitive. Only within composite path expressions does the double slash, as an abbreviation for descendant-or-self, produce a context-relative path overall.
When used alone with a following node test, or at the start of a composite path expression, it always produces an absolute path.
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