tags:

views:

373

answers:

1

Consider this condition that exists in a template that is called recursively:

<xsl:if test="$i &lt;= $count">

I'm using an XSLT 2.0 processor (Saxon-B 9.1.0.6). The condition seems to work only when running an XSLT 1.0 stylesheet. When the stylesheet version is set to 2.0 (as it should be), it stops working.

Any ideas why?

Here's the whole thing:

<xsl:template name="for.loop">
    <xsl:param name="i" />
    <xsl:param name="count" />

    <xsl:if test="$i &lt;= $count">
 ...
    </xsl:if>

    <!-- Repeat the loop by recursion -->
    <xsl:if test="$i &lt;= $count">
     <xsl:call-template name="for.loop">
      <xsl:with-param name="i">
       <xsl:value-of select="$i + 1" />
      </xsl:with-param>
      <xsl:with-param name="count">
       <xsl:value-of select="$count" />
      </xsl:with-param>
     </xsl:call-template>
    </xsl:if>
</xsl:template>

Thanks.

+1  A: 

Here is my suspicion: Depending on what data types $i and $count are, the "less than" test may fail in 2.0 (which supports more data types than 1.0), where in 1.0 an implicit conversion exists that does the right thing.

Try to convert the data to the right type before you compare it, e.g. using number().

Tomalak
That fixed it. I used number($count) in the 2nd <xsl:if> test. Strange why only one of the tests required the change.
Jonathan
I think both tests require the change, actually. Have you checked? Negating the condition (test="$count > $i") should let you know.
Tomalak
I reversed both conditions to test="$count >= $i". Now it works without the number function. What's going on?
Jonathan
Can you tell me what data type your parameters are of? (What select expressions do you use to initialize them?)
Tomalak
I retract my last comment. Both reversed conditions require the number function.
Jonathan