11.5 Variables and Parameters within Templates
Variables and Parameters within Templates
As well as being allowed at the top-level, both
xsl:variable and xsl:param are also
allowed in templates. xsl:variable is allowed anywhere
within a template that an instruction is allowed. In this case, the
binding is visible for all following siblings and their descendants.
Note that the binding is not visible for the xsl:variable
element itself. xsl:param is allowed as a child
at the beginning of an xsl:template element. In this
context, the binding is visible for all following siblings and their
descendants. Note that the binding is not visible for the
xsl:param element itself.
A binding
shadows another binding if the binding occurs at a point
where the other binding is visible, and the bindings have the same
name. It is an error if a binding established by an
xsl:variable or xsl:param element within a
template Shadows another binding
established by an xsl:variable or xsl:param
element also within the template. It is not an error if a binding
established by an xsl:variable or xsl:param
element in a template Shadows
another binding established by an xsl:variable or
xsl:param Top-level
element. Thus, the following is an error:
<xsl:template name="foo">
<xsl:param name="x" select="1"/>
<xsl:variable name="x" select="2"/>
</xsl:template>
However, the following is allowed:
<xsl:param name="x" select="1"/>
<xsl:template name="foo">
<xsl:variable name="x" select="2"/>
</xsl:template>
NOTE:
The nearest equivalent in Java to an xsl:variable
element in a template is a final local variable declaration with an
initializer. For example,
<xsl:variable name="x" select="'value'"/>
has similar semantics to
final Object x = "value";
XSLT does not provide an equivalent to the Java assignment operator
x = "value";
because this would make it harder to create an implementation that
processes a document other than in a batch-like way, starting at the
beginning and continuing through to the end.
|