Variables
xsl:variable
# This syntax is the safer of the two when assigning a string value
<xsl:variable name="name">text</name>
<xsl:variable name="name" [select="expr"]/>
- Declares a variable
- If the select expression is a string, it must be nested in
quotes (
"'...'", '"..."' ) so that it's
not treated as an XPath expression
- Referencing the variable: $name
- Referencing the variable outside of an XSLT tag: {$name}
- Placing curly braces around a variable causes it to be treated as
an XPath expression, rather than as a string literal
<xsl:variable name="name" select="'Harry'"/>
<xsl:value-of select="$name"/>
<a href="{$url}">text</a>
xsl:param
<xsl:param name="name" [select="expr"]>...</xsl:param>
- Declares a parameter
- The select attribute specifies the default value for the parameter
- Referencing the parameter: $name
- Referencing the parameter outside of an XSLT tag: {$name}
- Placing curly braces around a parameter causes it to be treated
as an XPath expression, rather than as a string literal
<xsl:value-of select="$url"/>
<a href="{$url}">text</a
xsl:with-param
<xsl:with-param name="name" [select="expr"]>...</xsl:with-param>
- Defines the value of a parameter to be passed into a template
- The name attribute must match a name in an
<xsl:param>
element