xsl-list
[Top] [All Lists]

RE: [xsl] Recursive for loop & xslt 2.0

2009-06-17 08:32:30
You are passing the parameters as strings rather than as numbers, so in XSLT
2.0 they will be compared as strings.

Instead of

  <xsl:with-param name="i">1</xsl:with-param>

write

  <xsl:with-param name="i" select="1"/>

and instead of

  <xsl:with-param name="count">
    <xsl:value-of select="$count"/>
  </xsl:with-param>

write

<xsl:with-param name="count" select="$count"/>

(This habit of using xsl:value-of inside xsl:variable or xsl:with-param,
rather than using the select attribute, is really bad XSLT coding, and yet
it seems to be so widely practiced it's impossible to eradicate. It's
long-winded, it's grossly inefficient, and in some cases, as here, it gives
the wrong answer.)

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


 

-----Original Message-----
From: Israel Viente [mailto:israel(_dot_)viente(_at_)gmail(_dot_)com] 
Sent: 17 June 2009 13:07
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Recursive for loop & xslt 2.0

Hi,

I used an example of a recursive for loop as below:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output method="html"/>

<xsl:template match="/">

<html>
<head><title>Say Hello Ten Times!</title></head> <body>
    <b>I am going to say hello Ten Times!</b>
<!-- begin_: Send_Loop_To_HTML -->
    <xsl:call-template name="for.loop">
     <xsl:with-param name="i">1</xsl:with-param>
     <xsl:with-param name="count">10</xsl:with-param>
    </xsl:call-template>
</body>
</html>

</xsl:template>


<!--begin_: Define_The_Output_Loop -->
  <xsl:template name="for.loop">

   <xsl:param name="i"      />
   <xsl:param name="count"  />

   <!--begin_: Line_by_Line_Output -->
   <xsl:if test="$i &lt;= $count">
      <br /> <b><xsl:value-of select="$i" />.</b>Hello world!
   </xsl:if>

   <!--begin_: RepeatTheLoopUntilFinished-->
   <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>
</xsl:stylesheet>

As soon as I change the xsl:stylesheet/@version to "2.0" it 
stops working as expected.

Can you please let me know what am I missing?

Thanks, Viente

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>