Re: [xsl] XSL Variable not getting set

Subject: Re: [xsl] XSL Variable not getting set
From: Abel Braaksma <>
Date: Wed, 14 Mar 2007 14:39:22 +0100
mIchael wolff wrote:

I am using Saxon 8.8 and and trying to set a variable
when a certain value is found in the node list.

Setting a variable is something not possible in XSLT.

When I walk through the code with XMLSpy debug, I see
that the variable never gets set. In fact, it skips
everything between the <xsl:variable> tags and goes
right to the line: <xsl:if test="not(Found)">

If you use XMLSpy Debug, you are not using Saxon anymore, but the internal XMLSpy parser, which is likely to do things differently, more so because it is still in the stages of adopting the xslt recommendation.

Does anyone know what is wrong with this template?

<xsl:variable name="Found"> <xsl:for-each select="current-group()"> <xsl:sort data-type="number" order="ascending"/>

You have a 'current-group()' here. But you do not have a xsl:for-each-group instruction. The current-group function will return the empty sequence when there is not xsl:for-each-group and as a result, the xsl:for-each in your code has nothing to do, which results in the empty sequence for the variable 'Found'.

The reason that the debugger does not step over it is probably because XMLSpy has optimized it away. If you could step over it using Saxon, you likely encountered the same behavior. For a processor, if it encounters your code, regardless the input, '$Found' will contain the empty sequence always.

As a consequence, your line with '<xsl:if test="not(Found)"> ' is the first stop for the debugger (nothing else to do before that).

-- Abel Braaksma

Current Thread