Using the following-sibling Axis

The following-sibling axis contains all the following siblings of the context node.

For example, I can match each <PLANET> element and copy all the nodes in the following-sibling axis to the result document like this:

Listing 7.9. Using the following-sibling 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-sibling::*"> 
        <xsl:copy-of select="."/> 
    </xsl:for-each> 
</xsl:template> 

</xsl:stylesheet> 

This copies over the two siblings following Mercury first (Venus and Earth) then copies over the following sibling of Venus, which is Earth. Earth itself has no following ...

Get Inside XSLT 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.