Using the following Axis

Using the following Axis

The following axis contains all nodes that are after the context node in document order (in other words, in the order in which they appear in the document, starting at the beginning of the document), excluding any of the context nodes descendants and also excluding attribute nodes and namespace nodes.

In this example I match each <PLANET> element and copy all the following elements to the result document:

Listing 7.8 Using the following Axis
 <?xml version="1.0"?>  <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:output method="xml"/>  <xsl:template match="PLANET">      <xsl:for-each select="following::*">          <xsl:copy-of select="."/>      </xsl:for-each>  </xsl:template>  </xsl:stylesheet> 

Heres what the result looks like. Note that when this template matches Mercurys <PLANET> element, it copies all the following elements, which are Venus, then all the descendants of Venus, then Earth, then all the descendants of Earth. Next , it matches Venus <PLANET> element and copies all the following elementsthat is, Earth, and all of Earths descendants:

 <?xml version="1.0" encoding="UTF-8"?>      <PLANET>          <NAME>Venus</NAME>          <MASS UNITS="(Earth = 1)">.815</MASS>          <DAY UNITS="days">116.75</DAY>          <RADIUS UNITS="miles">3716</RADIUS>          <DENSITY UNITS="(Earth = 1)">.943</DENSITY>          <DISTANCE UNITS="million miles">66.8</DISTANCE><!--At perihelion-->      </PLANET>      <NAME>Venus</NAME>      <MASS UNITS="(Earth = 1)">.815</MASS>      <DAY UNITS="days">116.75</DAY>      <RADIUS UNITS="miles">3716</RADIUS>      <DENSITY UNITS="(Earth = 1)">.943</DENSITY>      <DISTANCE UNITS="million miles">66.8</DISTANCE>      <PLANET>          <NAME>Earth</NAME>          <MASS UNITS="(Earth = 1)">1</MASS>          <DAY UNITS="days">1</DAY>          <RADIUS UNITS="miles">2107</RADIUS>          <DENSITY UNITS="(Earth = 1)">1</DENSITY>          <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion-->      </PLANET>      <NAME>Earth</NAME>      <MASS UNITS="(Earth = 1)">1</MASS>      <DAY UNITS="days">1</DAY>      <RADIUS UNITS="miles">2107</RADIUS>      <DENSITY UNITS="(Earth = 1)">1</DENSITY>      <DISTANCE UNITS="million miles">128.4</DISTANCE>      <PLANET>          <NAME>Earth</NAME>          <MASS UNITS="(Earth = 1)">1</MASS>          <DAY UNITS="days">1</DAY>          <RADIUS UNITS="miles">2107</RADIUS>          <DENSITY UNITS="(Earth = 1)">1</DENSITY>          <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion-->      </PLANET>      <NAME>Earth</NAME>      <MASS UNITS="(Earth = 1)">1</MASS>      <DAY UNITS="days">1</DAY>      <RADIUS UNITS="miles">2107</RADIUS>      <DENSITY UNITS="(Earth = 1)">1</DENSITY>      <DISTANCE UNITS="million miles">128.4</DISTANCE> 

On the other hand, if you use the following-sibling axis, then only the following siblingsthat is, only <PLANET> elementsare copied to the result document, as youll see in the next section.



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

Similar book on Amazon

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