Re: [xsl] What's evaluated first: @select or xsl:with-param?

Subject: Re: [xsl] What's evaluated first: @select or xsl:with-param?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 18 Oct 2010 16:40:58 +0100
The specification leaves this implementation-defined. Since the values of the parameters are the same for every node processed, it's a reasonably strategy for the processor to evaluate the parameters before knowing how many selected nodes there are, though I guess an even better strategy would be to do it lazily when the first selected node is found.

But note also that this is a type error, and that type errors can even be reported at compile-time, even if the apply-templates is never executed. This could happen for example if the variable $b can be evaluated at compile time and its value is known statically to be an empty sequence.

Michael Kay
Saxonica

On 18/10/2010 16:19, Vladimir Nesterovsky wrote:
Hello!

I've seen a code like this:
----------
<xsl:variable name="a" as="element()?" select="..."/>
<xsl:variable name="b" as="element()?" select="..."/>

<xsl:apply-templates select="$a">
   <xsl:with-param name="b" tunnel="yes" as="element()" select="$b"/>
</xsl:apply-templates>
----------

It fails with an error:
"An empty sequence is not allowed as the value of parameter $b".

What is interesting is that the value of $a is an empty sequence,
so the code could potentially work, provided processor evaluated $a first,
and decided not to evaluate xsl:with-param.

Whether the order of evaluation of @select and xsl:with-param is specified

by the standard or it's an implementation defined?

Current Thread