[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] strings and recursive templates


Subject: [xsl] strings and recursive templates
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Fri, 19 Jul 2002 12:09:13 +0100


I would have thought the following templates should produce the same
result, one uses choose/when, one uses if, however the value-of at the
end of template t2 seems to keep track of the whole string... if I step
through the code the debugger stays on that line the number of times the
template has been recursively called - which is a bit strange...

Using this data:
  
<node>1 | 2 | 3 | 4 | 5</node>

I would expect this result:

1 2 3 4 5

which is what t1 gives me, whereas t2 produces:

 1  2  3  4  5 4 | 5 3 | 4 | 5 2 | 3 | 4 | 51 | 2 | 3 | 4 | 5

why is this? saxon and msxml4 both produce the same so Im guessing its a
gap in my understanding rather than a processor issue...

<xsl:template name="t1">
  <xsl:param name="string" select="''"/>
  <xsl:choose>
    <xsl:when test="contains($string,'|')">
      <xsl:value-of select="substring-before($string,'|')"/>
      <xsl:call-template name="t1">
        <xsl:with-param name="string"
select="substring-after($string,'|')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
   </xsl:choose>
</xsl:template>


<xsl:template name="t2">
  <xsl:param name="string" select="''"/>
    <xsl:if test="contains($string,'|')">
      <xsl:value-of select="substring-before($string,'|')"/>
      <xsl:call-template name="t2">
        <xsl:with-param name="string"
select="substring-after($string,'|')"/>
      </xsl:call-template>
    </xsl:if>
      <xsl:value-of select="$string"/>
</xsl:template>


cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.373 / Virus Database: 208 - Release Date: 01/07/2002
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords