The order of evaluation is, in general, not guaranteed except where such guarantees follow from dependencies of expressions. For example:
<xsl:variable name="foo" value="123" />
<xsl:variable name="bar" value="456" />
<xsl:variable name="baz" value="$foo + $bar" />
<xsl:variable name="dummy" value="42 div 0" />
<xsl:template match="/">
<xsl:value-of select="$baz"/>
</xsl:template>
Here, it is certain that baz
will get evaluated at some point prior to being output -maybe only immediately before being output, maybe at startup, maybe somewhere in between - and that foo
and bar
will be evaluated before baz
- but the relative order of evaluation for foo
and bar
is not defined.
dummy
is an interesting case. It's not actually used anywhere, and so could be omitted entirely, but, if my understanding of the spec is correct, the processor must nonetheless raise an error as if it was evaluated. At which point it does so is not important, because there's no way to tell from inside XSLT - so dummy
will be evaluated at some unspecified moment during execution (could be the first thing it does, or the last after all output is already generated), but is guaranteed to cause the transformation to fail with an error.
This is all about XSLT and XPath 1.0. In 2.0, it is more relaxed - evaluation isn't even required to happen at all; if processor can obtain a valid result by skipping evaluation of some expressions where otherwise they would result in error, it has a blanket permission to do so.