Subject: Re: [xsl] defaulting empty node to zero From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Fri, 24 May 2002 22:34:48 +0200 |
I want to find the numeric value of a node. If the node is empty (e.g.: <taxAmount/>) I want zero. I also want zero when applying sum() to the same or a set of similar nodes.
Is there a solution to this problem other than setting a variable, check the variable = NaN, return the variable or zero?
Chuck
XML: <root> <test>1</test> <test>2</test> <test>3</test> <test>4</test> <test></test> <test>1</test> <test>2</test> <test>3</test> <test>4</test> </root>
XSLT: <xsl:template match="root"> <xsl:apply-templates select="test[1]"/> </xsl:template>
<xsl:template match="test"> <xsl:param name="sum" select="0"/> <xsl:variable name="newsum"> <xsl:choose> <xsl:when test="number(.)"> <xsl:value-of select="$sum + ."/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$sum"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:apply-templates select="following-sibling::test[1]"> <xsl:with-param name="sum" select="$newsum"/> </xsl:apply-templates> <xsl:if test="not(following-sibling::test)"> <xsl:value-of select="$newsum"/> </xsl:if> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] defaulting empty node to zero, Chuck Paussa | Thread | Re: [xsl] defaulting empty node to , Wendell Piez |
Re: [xsl] Assigning variable values, Georges Claessen | Date | [xsl] Newbie question cont--transfo, Grant-Kathryn |
Month |