I am considering using either <xsl:param> or <xsl:variable> when defining an <xsl:template name="myTemplate"> that will be called in another XSL file.
Legacy code seems to use xsl:variable when being used in <xsl:template match="legacyTemplate">.
So what’s the difference between xsl:param and xsl:variable when using it in <xsl:template name="myTemplate">?
The difference is that the value of an
xsl:paramcould beset outside the context in which it is declared. For example,
see:
then you know that
$vwill always give you the string'y'. But for$pthe string'x'is only a default:you will see a different value if the template is invoked with either
xsl:apply-templatesorxsl:call-templatewhich contains an instructionsuch as:
<xsl:with-param name="p" select="'not x'" /><xsl:param>may also be used outsidexsl:template, at the top level inthe stylesheet. The value of such a parameter may be set when the
XSLT processor is called. How this is done depends on the processor
and whether you call it from the command line or by program.