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

RE: Calling a template recursively

Subject: RE: Calling a template recursively
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Mon, 5 Jul 2004 07:20:32 +0100
xsl call template recursively
> Hello List,
>           I am using following template to display a
> <br> tag after every 25th character of the string. But
> that does not seem to work.
> 
> <xsl:template name="normaliseString">
> 		<xsl:param name="releaselevel"/>
> 		<xsl:variable name="temp" 
> select="substring($releaselevel,1,25)"/>
> 		<xsl:value-of select="$temp"/>
> 		<xsl:text>&lt;br&gt; </xsl:text>
> 		<xsl:if test="string-length($releaselevel) >25">
> 			
> 			<xsl:variable name="temp2" 
> select="substring($temp,26,string-length($releaselevel))"/>
> 			<xsl:value-of select="$temp2"/>
> 			<xsl:call-template name="normaliseString">
> 				<xsl:with-param  name="releaselevel"
> select="@temp2"/>
> 				</xsl:call-template>
> 		</xsl:if>
> 		
> 	</xsl:template>
> 
> any suggestion.


Hi,

You forgot to say why your template 'didn't seem to work' so I've had to
guess ;-)  I think you just want the standard tail-recursive string
processing template.  This involves ensuring the recursive part of the
template is the last operation in the template, allowing the compiler to
flatten the recursion into a set of if-elses (which is more memory
efficient).  

<xsl:template name="normaliseString">
  <xsl:param name="releaselevel"/>
  <xsl:choose>
    <xsl:when test="string-length($releaselevel) &lt; 25">
      <xsl:value-of select="$releaselevel"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="substring($releaselevel, 1, 25)"/>
      <br/>
      <xsl:call-template name="normaliseString">
        <xsl:with-param name="releaselevel"
select="substring($releaselevel, 25)"/>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

cheers
andrew

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.