<xsl:variable name="" select="" >
- To save a node-set, string, number, boolean or result tree fragment for later use
- Variables are single assignment (no side effects) mathematical variables
- Can be global, or local to a template and are lexically scoped
- Variable accessed by placing $ in front of name
<xsl:variable name="varempty" /> No selection made, empty
<xsl:variable name="varnumber" select="23" /> Recognised as number
<xsl:variable name="varstring" select="'a string'" />Quotes indicate string
<xsl:variable name="varfragment">
<cd><artist>Armstrong</artist><title>My New Album</title></cd>
</xsl:variable>
<xsl:if test="position() = last()">
<xsl:variable name="final">Completed</xsl:variable> Invalid outside if
</xsl:if>
<xsl:variable name="final"> Variable final can be used ouside if
<xsl:if test="position() = last()">Completed</xsl:if>
</xsl:variable>
<xsl:value-of select="$varstring" /> Using a variable
<xsl:copy-of select="$varfragment" />
<variable name="template_result"> Pass value out of template
<apply-templates select="cdlist" /> Result to the variable not Result Tree
</xsl:variable>