With element xsl:next-match matching templates with lower priority can be called from a matching template of higher priority.
In this example the template "*[1]" is used first for bbb element as it has explicit priority "1000". The next matching element is "bbb" and the last "*", so these three templates are applied in this order (with help of xsl:next-match). The ccc is matched with "ccc" template and then the "*" template is applied as in "bbb" case.
|
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="/aaa"> <xxx> <xsl:apply-templates select="*"/> </xxx> </xsl:template> <xsl:template match="*"> <yyy> <xsl:value-of select="3*."/> </yyy> </xsl:template> <xsl:template match="*[1]" priority="1000"> <zzz> <xsl:next-match/> </zzz> </xsl:template> <xsl:template match="bbb"> <xsl:copy-of select="."/> <xsl:next-match/> </xsl:template> <xsl:template match="ccc"> <ppp> <xsl:next-match/> </ppp> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb>12</bbb> <ccc>12</ccc> </aaa> |
Output
<zzz> <xxx> <zzz> <bbb>12</bbb> <yyy>36</yyy> </zzz> <ppp> <yyy>36</yyy> </ppp> </xxx> </zzz> |
| Previous chapter: | - - - |
| Next chapter: | Sequences |
| Previous page: | Implicit priorities |
| Next page: | - - - |