The f:assign element works like xsl:variable, but forces both a local
and a global variable binding, replacing any other in-scope bindings
having the same expanded-name. Thus, it can be used to circumvent XSLT's
restriction on variables not being reassignable. However, its use is not
recommended, for reasons explained below.
As with xsl:variable, the name of the variable is given in the mandatory
name attribute, and the new value may be given either by an expression in
the select attribute, or by instantiating the content of the element.
If no select attribute is given, then a body-as-ns attribute may be used
to indicate whether to assign the variable to the contents as a node-set
(value 'yes') or as a result tree fragment (default, or value 'no').
In either case, be aware that the node-set or result tree fragment will
have a root node.
Note that reassignment of variables is generally never actually needed.
Before using f:assign, read the XSL FAQ or ask on xsl-list if there is a
better, more portable way to solve your problem.
XSLT is designed as a language that is free of side-effects, which is
why assignment is not allowed and variables have very specific scope.
When variable assignment is allowed, certain optimizations in the XSLT
processor become impossible. Also, there are some circumstances in which
the order of execution may not be quite what you expect, in which case
f:assign may show anomalous behavior. It does not work predictably when
called from within a tail-recursive template, for example.
That said, f:assign can be a convenient way to create a node-set from
a result tree fragment in XSLT 1.0. The proper way to do this is with
EXSLT: <xsl:variable name="rtf"><foo/></xsl:variable>
<xsl:variable name="ns" select="exsl:node-set($rtf)" xmlns:exsl="http://exslt.org/common"/>
but f:assign can do it in one step:
<f:assign name="ns" body-as-ns="yes"><foo/></f:assign>
Methods
Fields
legalAttrs = {'body-as-ns': <Ft.Xml.Xslt.AttributeInfo.YesNoAvt instance>, 'name': <Ft.Xml.Xslt.AttributeInfo.QName instance>, 'select': <Ft.Xml.Xslt.AttributeInfo.Expression instance>}
Fields
Fields