Axes
Each XPath location step moves along an axis from a
context node. The context node is a particular root,
element, attribute, comment, processing-instruction, namespace, or
text node in the XML document. (In practice, it’s almost always an
element node or the root node.) The context node may be a node
selected by the previous location step in the location path, or it
may be determined by extra-XPath rules, such as which node is
matched by an xsl:template
element.
However the context node is determined, it has some relationship to every other node in the document. The various axes divide the document into different overlapping sets, depending on their relationship to the context node. There are exactly 13 axes you can use in an XPath location step:
childAll children of the context node. Only root and element nodes have children. Attribute and namespace nodes are not children of any node, although they do have parent nodes.
descendantAll nodes contained inside the context node—that is, a child node, a child of a child node, a child of a child of a child node, and so on. Only root and element nodes have descendants. Like the
childaxis, thedescendantaxis never contains attribute or namespace nodes.descendant-or-selfAny descendant of the context node or the context node itself.
//is an abbreviation for/descendant-or-self::node( )/.parentThe element or root node that immediately contains the context node. Only the root node does not have a parent node.
..is an abbreviation for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access