[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi Susan,
If the operation is a simple sum, why not use the inherent XSLT function sum and let the XPath pick out the right nodes for you?
BTW a number(.) also returns 'NaN' if the node's string value is nothing (""), so some of the tests you do are not necessary anyway (MK's XSLT Programmers Ref. 2nd. ed., p. 532).
I would expect something like this to work:
result = <xsl:value-of select="sum(nodeset-containing-prices[number(translate(.,'$',''))!='NaN'])"/>
where nodeset-containing-prices should be exchanged with the nodeset you use in the $price parameter first time the template total_value is called.
I hope this helps
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
RE: [xsl] tail recursion and NaN
Subject: RE: [xsl] tail recursion and NaN From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx> Date: Sat, 08 May 2004 08:56:01 +0000 |
Hi Susan,
If the operation is a simple sum, why not use the inherent XSLT function sum and let the XPath pick out the right nodes for you?
BTW a number(.) also returns 'NaN' if the node's string value is nothing (""), so some of the tests you do are not necessary anyway (MK's XSLT Programmers Ref. 2nd. ed., p. 532).
I would expect something like this to work:
result = <xsl:value-of select="sum(nodeset-containing-prices[number(translate(.,'$',''))!='NaN'])"/>
where nodeset-containing-prices should be exchanged with the nodeset you use in the $price parameter first time the template total_value is called.
I hope this helps
Regards, Ragulf Pickaxe :)
From: "Susan Campbell" <SCampbell@xxxxxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: RE: [xsl] tail recursion and NaN Date: Fri, 7 May 2004 08:59:19 -0400
Thanks for the help. I later learned I also had to test for a dollar sign as well as empty cells. This is what I'm using. It works, but there may be a more compact/elegant way to do it.
sc
<xsl:template name="total-value"> <xsl:param name="price"/> <xsl:param name="result" select="0"/> <xsl:param name="nodollarsign" select="translate($price,'$','')"/> <xsl:choose> <xsl:when test="$price and number($price) = number($price)"> <xsl:call-template name="total-value"> <xsl:with-param name="price" select="$price[position() > 1]"/> <xsl:with-param name="result" select="$result + $price"/> </xsl:call-template> </xsl:when> <xsl:when test="$nodollarsign"> <xsl:call-template name="total-value"> <xsl:with-param name="price" select="$price[position() > 1]"/> <xsl:with-param name="result" select="$result + $nodollarsign"/> </xsl:call-template> </xsl:when> <xsl:when test="$price and number($price) != number($price)"> <xsl:call-template name="total-value"> <xsl:with-param name="price" select="$price[position() > 1]"/> <xsl:with-param name="result" select="$result"/> </xsl:call-template> </xsl:when> <xsl:otherwise><xsl:value-of select="$result"/></xsl:otherwise> </xsl:choose> </xsl:template>
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] tail recursion and NaN, Susan Campbell | Thread | [xsl] serialization exception, shadab |
[xsl] NullPointerException with Jav, Barry Lay | Date | [xsl] serialization exception, shadab |
Month |