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

RE: tail-recursion

Subject: RE: tail-recursion
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 28 Aug 2003 15:48:14 +0100
how to use tail
Your template parseRows is intrinsically tail-recursive - basically this
means that after calling itself, it does nothing else before returning.

It's a rather strange stylesheet because as well as using recursion to
tokenize the string, it also calls xalan:tokenize() - I can't see why!

Saxon and jd.xslt are known to use tail recursion.

To test whether your engine uses tail recursion (on a particular
stylesheet), generate some test data that will cause about 2000 nested
recursive calls. Most processors without tail recursion will fail at
around 500.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of I-Lin Kuo
> Sent: 28 August 2003 14:44
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  tail-recursion
> 
> 
> I have to do some string manipulation. The following takes a 
> string such as 
> "1~2~a~!~f~4~5~!~1~2~3" and parses it as a list delimited by 
> "~!~" and then 
> processes each list element "1~2~a", "f~4~5", and "1~2~3" as a list 
> delimited by "~" in order to display as an html table
> 
> 
> <xsl:template name="parseRows">
> 	<xsl:param name="catContents"/>
> 	<xsl:param name="font-size" select="'-1'"/>
> 	<xsl:choose>
> 		<xsl:when test="contains($catContents,'~!~')">
> 			<xsl:call-template name="parseRow">
> 				<xsl:with-param name="rowContents" 
> select="substring-before($catContents,'~!~')"/>
> 				<xsl:with-param 
> name="font-size" select="$font-size"/>
> 			</xsl:call-template>
> 			<xsl:call-template name="parseRows">
> 				<xsl:with-param name="catContents" 
> select="substring-after($catContents,'~!~')"/>
> 				<xsl:with-param 
> name="font-size" select="$font-size"/>
> 			</xsl:call-template>
> 		</xsl:when>
> 		<xsl:otherwise>
> 			<xsl:value-of select="$catContents"/>
> 		</xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>
> 
> <xsl:template name="parseRow">
> 	<xsl:param name="rowContents"/>
> 	<xsl:param name="font-size" select="'-1'"/>
> 	<tr>
> 		<xsl:for-each select="xalan:tokenize($rowContents,'~')">
> 			<td><font 
> size="{$font-size}"><xsl:value-of select="."/></font></td>
> 		</xsl:for-each>
> 	</tr>
> </xsl:template>
> 
> This code works, but I'm thinking of modifying it. I know 
> that some xslt 
> engines use tail recursion to optimise their processing and 
> I'm worried 
> about breaking that.
> 
> 1. Which xslt engines use tail recursion?
> 2. I'm not exactly sure about tail recursion. Does my xslt 
> above already 
> violate that? If not, what should I be careful about.
> 3. Is there a way for me to empirically test whether an xslt 
> engine uses 
> tail recursion?
> 
> I-Lin Kuo, Ann Arbor, MI
> Macromedia Certified ColdFusion 5.0 Advanced Developer
> Sun Certified Java 2 Programmer
> Ann Arbor Java Users Group (www.aajug.org) SUN Top 25 JUG
> 
> _________________________________________________________________
> Get MSN 8 and help protect your children with advanced 
> parental controls.  
> http://join.msn.com/?page=features/parental
> 
> 
>  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
  • tail-recursion
    • I-Lin Kuo - Thu, 28 Aug 2003 09:44:12 -0400 (EDT)
      • Michael Kay - Thu, 28 Aug 2003 10:47:16 -0400 (EDT) <=
      • <Possible follow-ups>
      • Andrew Welch - Thu, 28 Aug 2003 11:19:45 -0400 (EDT)
      • I-Lin Kuo - Thu, 28 Aug 2003 11:22:12 -0400 (EDT)
      • Andrew Welch - Thu, 28 Aug 2003 11:23:07 -0400 (EDT)

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.