Using the descendant-or-self Axis

Using the descendant-or-self Axis

The descendant-or-self axis contains all the descendants of the context node, and the context node itself. Note, however, that it does not contain any attributes or namespace nodes.

The following example puts this axis to work. In this case, I write a simplified stylesheet (see Chapter 2 for more on simplified stylesheets) to process all elements by using descendants to produce the HTML table of planetary data youre already familiar with:

Listing 7.7 Using the descendant-or-self Axis
 <HTML xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl::version="1.0">      <HEAD>          <TITLE>             The Planets Table          </TITLE>      </HEAD>      <BODY>          <H1>             The Planets Table          </H1>          <TABLE BORDER="2">             <TR>                  <TD>Name</TD>                  <TD>Mass</TD>                  <TD>Radius</TD>                  <TD>Day</TD>             </TR>             <xsl:for-each select="/descendant-or-self::node()/PLANET">                 <TR>                     <TD><xsl:value-of select="NAME"/></TD>                     <TD><xsl:value-of select="MASS"/></TD>                     <TD><xsl:value-of select="RADIUS"/></TD>                     <TD><xsl:value-of select="DAY"/></TD>                 </TR>              </xsl:for-each>          </TABLE>      </BODY>  </HTML> 

Thats all it takes. Im using a simplified stylesheet here to point out that using a descendant axis such as descendant or descendant-or-self enables you to work through all matching nodes automatically, much as an <xsl:for-each> or <xsl:template> element does.



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