saxon:assign instruction is used to change the value of a global
variable that has previously been declared using xsl:variable (or xsl:param). The variable or parameter must be marked as
assignable by including the extra attribute saxon:assignable with value
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element
The name of the variable
The new value may be given either by an expression in the
This instruction works only with global variables. It should be regarded as deprecated, and may be withdrawn completely at some time in the future, since it is incompatible with many of the optimizations that Saxon now performs.
There are better ways of achieving the same effect. Consider constructs such
as tunnel parameters,
xsl:iterate, higher-order functions, or
saxon:assign is used then multithreading should be disabled by setting
the configuration property ALLOW_MULTITHREADING to false.
A compile-time warning is issued if multi-threading is allowed, since the order of execution
of instructions in the stylesheet is then unpredictable.
The new value is converted to the declared type of the variable using the function conversion rules. This may result in a type error if conversion is not possible.
saxon:assign element itself does not allow an
Instead, it calculates the value of the variable as if
specified. This means that the result of the construct:
is a single text node, not a document node containing a text node. If you want to create a document node, use xsl:document.
saxon:assign is cheating. XSLT is designed as a
language that is free of side-effects, which is why variables are not assignable. Once
assignment to variables is allowed, certain optimizations become impossible.
There are some circumstances in which the order of execution may not be quite what you
expect, in which case
saxon:assign may show anomalous behavior. In particular,
avoid calling saxon:assign while evaluating variables, or from within a function called
from a context such as a predicate. In principle
saxon:assignable attribute is designed to stop Saxon doing optimizations
that cause such anomalies, but you can't always rely on this.
Saxon issues a warning if
saxon:assign is used in a configuration that
allows multi-threading, since the construct is not thread-safe. Multi-threading can be
disabled using the configuration property ALLOW_MULTITHREADING.
saxon:assign instruction can be exported to a SEF file; the resulting SEF file
can be used by Saxon/J but not by Saxon-JS.