[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: defaulting empty node to zero
Chuck Paussa wrote:
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. Hi Chuck, you need another approach for this. Process the elements step by step: 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> Regards, Joerg XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|