next-match_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1" name="Delta" price="3250" stock="4"/>
<product
id="p2" name="Golf" price="1000" stock="5"/>
<product
id="p3" name="Alpha" price="1200" stock="19"/>
</products>
next-match_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<PRODUCTS>
<xsl:apply-templates/>
</PRODUCTS>
</xsl:template>
<xsl:template
match="product">
<PRODUCT
id="{@id}" price="{@price}" stock="{@stock}"/>
</xsl:template>
<xsl:template
match="product[@id = 'p2']">
<PRODUCT
id="{@id}" price="{@price * 1.25}" stock="{@stock}"/>
</xsl:template>
<xsl:template
match="product|product[@id = 'p2']">
<xsl:comment>
<xsl:value-of
select="concat(' ', @name, ' ')"/>
</xsl:comment>
<xsl:text>
</xsl:text>
<xsl:next-match/>
</xsl:template>
</xsl:stylesheet>
next-match_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<PRODUCTS>
<!-- Delta -->
<PRODUCT
id="p1" price="3250" stock="4"/>
<!-- Golf -->
<PRODUCT
id="p2" price="1250" stock="5"/>
<!-- Alpha -->
<PRODUCT
id="p3" price="1200" stock="19"/>
</PRODUCTS>
xsl:next-match is new in XSLT 2.0. Let us say that we need to insert a comment before all "product" elements matched by very many templates. We need only one new template creating the comment and then xsl:next-match.
Updated 2009-03-19