[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: strings and recursive templates

Subject: RE: strings and recursive templates
From: "Américo Albuquerque" <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Fri, 19 Jul 2002 12:30:42 +0100
call recursively templates in xsl
Hi Andrew

<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"/> <---- here his your problem it
shows the string even when a match is found
</xsl:template>

change that line to:
<xsl:if test="not(contains($string,'|'))">
 <xsl:value-of select="$string"/>
</xsl:if>

and it should work

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Andrew Welch
Sent: Friday, July 19, 2002 12:09 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  strings and recursive templates




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



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.