|
Subject: RE: [xsl] tail recursion and NaN From: <Jarno.Elovirta@xxxxxxxxx> Date: Tue, 4 May 2004 08:52:46 +0300 |
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>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] tail recursion and NaN, Susan Campbell | Thread | RE: [xsl] tail recursion and NaN, Jarno.Elovirta |
| [xsl] date:difference function in x, Ravi Chayanam | Date | RE: [xsl] tail recursion and NaN, Jarno.Elovirta |
| Month |