Part 1 of XPath Location Steps: Axes

Part 1 of XPath Location Steps: Axes

In the location path ancestor :: NAME , which refers to a <NAME> element that is an ancestor of the context node, ancestor is the axis. XPath supports many different axes, and heres the complete list:

  • The ancestor axis holds the ancestors of the context node; the ancestors of the context node are the parent of context node and the parents parent and so forth, back to and including the root node.

  • The ancestor-or-self axis holds the context node and the ancestors of the context node.

  • The attribute axis holds the attributes of the context node.

  • The child axis holds the children of the context node.

  • The descendant axis holds the descendants of the context node. A descendant is a child or a child of a child and so on.

  • The descendant-or-self axis contains the context node and the descendants of the context node.

  • The following axis holds all nodes in the same document as the context node that come after the context node.

  • The following-sibling axis holds all the following siblings of the context node. A sibling is a node on the same level as the context node.

  • The namespace axis holds the namespace nodes of the context node.

  • The parent axis holds the parent of the context node.

  • The preceding axis contains all nodes that come before the context node.

  • The preceding-sibling axis contains all the preceding siblings of the context node. A sibling is a node on the same level as the context node.

  • The self axis contains the context node.

In the following example template I use the descendant axis to indicate that I want to match descendants of the context node, which include child nodes, grandchild nodes, great-grandchild nodes, and so on:

 <xsl:template match="PLANET">      <DATA>          <NAME>              <xsl:value-of select="descendant::NAME"/>          </NAME>          <MASS>              <xsl:value-of select="descendant::MASS"/>          </MASS>          <DAY>              <xsl:value-of select="descendant::DAY"/>          </DAY>      </DATA>  </xsl:template> 

This chapter looks at each of these axes. In this example, descendant is the axis, and the element names NAME , MASS , and DAY are node tests .



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net