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

RE: tail recursion and NaN

Subject: RE: tail recursion and NaN
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Tue, 4 May 2004 08:52:46 +0300
nan xsl
Hi,

> <!--This is the template with recursion to add the prices, 
> needs test for NaN-->
> <xsl:template name="total-value">
>    <xsl:param name="price"/>
>    <xsl:param name="result" select="0"/>
> 	   <xsl:choose>
> 	     <xsl:when test="$price">
> 		<xsl:call-template name="total-value">
> 		   <xsl:with-param name="price" 
> select="$price[position() &gt; 1]"/>
> 		   <xsl:with-param name="result" 
> select="($result + $price)"/>

E.g.Replace this with

  <xsl:with-param name="result">
    <xsl:choose>
      <xsl:when test="string(number($price[1])) = 'NaN'">
        <xsl:value-of select="$result"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$result + $price[1]"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:with-param>

or place the test outside the xsl:call-template to pass the $result always as a number.

> 		</xsl:call-template>
> 	     </xsl:when>
> 		<xsl:otherwise><xsl:value-of 
> select="$result"/></xsl:otherwise>
>              </xsl:choose> 
> </xsl:template>

Quick test reveals that e.g. in Saxon 6.5.3 if you keep the $price bound to the same node-set and use a $cursor to point to the node being processed, with large documents the processing time goes down a third. Though you have to test if it helps your complete stylesheets and is faster in your choise of XSLT engine.

Cheers,

Jarno - this weeks Real Synthetic Audio <http://www.synthetic.org/play.html>

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.