|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: tail recursion and NaN
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() > 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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








