xsl:variable
Used to declare a variable and give it a value. If it appears at the top level
(immediately within xsl:stylesheet
) it declares a global variable,
otherwise it declares a local variable that is visible only within the
stylesheet element containing the xsl:variable
declaration. The
value of a variable can be referenced within an expression using the syntax
$name
.
Category: declaration
Category: instruction
Content:
sequence-constructor
Permitted parent elements:
xsl:stylesheet
; xsl:transform
; xsl:override
; xsl:function
; any XSLT element whose content model is sequence
constructor; any literal result element
Attributes
|
|
Defines the name of the variable. |
|
|
The value of the variable may be defined
either by an expression within the optional |
|
|
Defines the type of the variable. The actual supplied value must be an instance of this type; it will not be converted. (This changed in Saxon 7.4: previous releases did a conversion.) |
|
|
|
|
|
Notes on the Saxon implementation
In standard XSLT, variables once declared cannot be updated. Saxon however
provides a saxon:assign extension element to circumvent this restriction. The
extension attribute saxon:assignable must be set to
yes
on the xsl:variable
in order to use this
feature.
Examples
<xsl:variable name="title">A really exciting document"</xsl:variable> <xsl:variable name="backcolor" expr="'#FFFFCC'" /> <xsl:template match="/*"> <HTML><TITLE><xsl:value-of select="$title"/></TITLE> <BODY BGCOLOR='{$backcolor}'> ...</BODY></HTML> </xsl:template>