Axes in XPath expressions define "direction of movement" in the source document. The axes names are followed by "::" in XPath expressions.
The "child::" axis is the most commonly used axis in XPath expressions. It is the default axis and so it is not usually explicitly given. The child axis of an element contains all children of this element.
The xxx example compares if two nodes are equal. On the left side the "child::" axis is explicitly given on the right side the axis is not specified and so default axis is used.
The "parent::" axis reverses the direction of child axis. A node cannot have more than one parent. In the yyy example the expression at first descends to bbb element and then returns to its parent aaa.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/"> <xxx> <xsl:value-of select="/child::aaa/child::bbb is /aaa/bbb"/> </xxx> <yyy> <xsl:value-of select="/aaa/bbb/parent::aaa is aaa"/> </yyy> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb/> </aaa> |
Output
<xxx>true</xxx> <yyy>true</yyy> |
| Previous chapter: | Sorting |
| Next chapter: | Named-Templates |
| Previous page: | Steps |
| Next page: | Descendant and ancestor axes |