Subject: Re: [xsl] A more concise way to handle empty numeric elements From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Thu, 07 Jun 2007 15:17:36 +0200 |
I have to process an XML file that contains a lot of numeric data. Many of the elements that have no value are empty instead of being zero and it may differ for each line, for example
<line id=1> <cost1>1000</cost1> <cost2>0</cost2> <!-- 0 here, but empty in next line --> <cost3></cost3> </line> <line id=2> <cost1>2000</cost1> <cost2></cost2> <cost3>3000</cost3> </line>
I want to do:
<xsl:for-each select="line"> <xsl:value-of select="format-number(cost1 + cost2 + cost3,'#,###')"/> </xsl:for-each>
However, the empty elements will cause "NaN" to be displayed
Can't you simply do <xsl:value-of select="format-number(sum(*[text()]),'#,###')"/> That way only elements which have a text content are summed up.
Martin Honnen http://JavaScript.FAQTs.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] A more concise way to han, Andrew Welch | Thread | RE: [xsl] A more concise way to han, Michael Kay |
Re: [xsl] A more concise way to han, Andrew Welch | Date | Re: [xsl] Dynamically setting names, Andrew Welch |
Month |