If xsl:with-param instruction is used inside xsl:apply-templates the parameter value is passed to a matching template. If we call another template from the matching one, the value of the parameter is not passed.
Sometime it is useful to have this parameter available to further templates as well. In this case xsl:with-param bears the attribute tunnel with value "yes". If the target template uses xsl:param with the tunnel attribute set to "yes", tunneling of parameters is accomplished.
|
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"> <xsl:apply-templates select="bbb"> <xsl:with-param name="parA" select="1" tunnel="no"/> <xsl:with-param name="parB" select="9" tunnel="yes"/> </xsl:apply-templates> </xsl:template> <xsl:template match="bbb"> <xsl:param name="parA"/> <xsl:param name="parB"/> <bbb-final> <xsl:text>[</xsl:text> <xsl:value-of select="$parA"/> <xsl:text> - </xsl:text> <xsl:value-of select="$parB"/> <xsl:text>]</xsl:text> </bbb-final> <xsl:apply-templates select="ccc"/> </xsl:template> <xsl:template match="ccc"> <xsl:param name="parA" tunnel="yes"/> <xsl:param name="parB" tunnel="yes"/> <ccc-final> <xsl:text>[</xsl:text> <xsl:value-of select="$parA"/> <xsl:text> - </xsl:text> <xsl:value-of select="$parB"/> <xsl:text>]</xsl:text> </ccc-final> </xsl:template> </xsl:stylesheet> |
|
|
XML
<aaa> <bbb> <ccc/> </bbb> </aaa> |
Output
<bbb-final>[1 - ]</bbb-final> <ccc-final>[ - 9]</ccc-final> |
| Previous chapter: | Named-Templates |
| Next chapter: | Stylesheet Functions |
| Previous page: | Difference between parameters and variables |
| Next page: | - - - |