XPath Axes
The XPath specification defines 13 different axes; each axis contains various nodes. The nodes that are in a given axis depend on the context node. All 13 axes, excerpted from our more involved discussion in The XPath Data Model” in Chapter 3, are listed here.
child
axisContains the children of the context node. As we’ve already mentioned, the XPath expressions
child::lines/child::line
andlines/line
are equivalent. If an XPath expression (such assonnet
) doesn’t have an axis specifier, thechild
axis is used by default.parent
axisContains the parent of the context node, if there is one. (If the context node is the root node, the
parent
axis returns an empty node-set.) As a step in an XPath expression, theparent
axis can be abbreviated with the double period (..
); this moves up to the current node’s parent. If the<first-name>
and<last-name>
elements are both children of the<author>
element, and the context node is the<first-name>
element, the expressions../last-name
,parent::author/last-name
andparent::*
/last-name
are equivalent. If the context node does not have a parent, this axis returns an empty node-set.self
axisContains the context node itself. As a step in an XPath expression, the
self
axis can be abbreviated with a single period (.
). The expressions.
,self::node()
, andself::*
are equivalent in XSLT 1.0.[2.0] In XSLT 2.0, the
self
axis selects the context item, which might not be a node. If the context item is an atomic value, the expressionsself::node() ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.