Variables and parameters
- for reusing results of computations and parameterizing templates and
whole stylesheets
- static scope rules
- can hold any XPath value (string, number, boolean, node-set) +
result-tree fragment
- purely declarative: variables cannot be updated
- can be global or local to a template rule
Declaration:
- <xsl:variable name="..." select="expression"/>
- variable declaration for normal XPath value
- <xsl:variable name="..."> template </..>
- variable declaration for result tree fragment
(template is instantiated to give value)
- <xsl:param name="..." select="expression"/>
- parameter declaration for normal XPath value
(the value is the default value of the parameter)
- <xsl:param name="..."> template </..>
- parameter declaration for result tree fragment
Use:
- $name
- returns XPath value in expressions, e.g. attribute value templates
(recall that XPath context contains variable bindings)
- <xsl:with-param name=".." select="..."/> and
<xsl:with-param name="..."> template </..>
- passes parameters in xsl:call-template or xsl:apply-templates
Note: result tree fragments held by variables or parameters can be used
as source in pattern matching and template instantiation!