Subject: Re: [xsl] sum of price * qty, without node-set() From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 28 Jan 2004 23:09:24 -0500 |
i'm a newbie and am trying to get a sum of a calculation; i'm hoping to get the value "162.00".
...
so, i'd really like to be able to do this in native XSLT 1.0 (without node-set). could someone please point me in the right direction?
seems like it would be really simple.
i've been pounding my head for hours.
T:\ftemp>type gebhard.xml <BATCH> <RECEIPT> <qtyRcpt>1</qtyRcpt> <line> <pr>102.00</pr> </line> </RECEIPT> <RECEIPT> <qtyRcpt>3</qtyRcpt> <line> <pr>20.00</pr> </line> </RECEIPT> </BATCH>
T:\ftemp>type gebhard.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:variable name="result-text"> <xsl:text/>0<xsl:apply-templates select="/*/RECEIPT[1]" mode="equation"/> </xsl:variable> <xsl:variable name="result" select="number($result-text)"/>
<xsl:value-of select="$result"/> </xsl:template>
<xsl:template match="RECEIPT" mode="equation"> <xsl:param name="result" select="0"/> <xsl:variable name="this" select="$result + ( qtyRcpt * line/pr )"/> <xsl:choose> <xsl:when test="following-sibling::RECEIPT"> <xsl:apply-templates select="following-sibling::RECEIPT[1]" mode="equation"> <xsl:with-param name="result" select="$this"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:value-of select="$this"/> </xsl:otherwise> </xsl:choose> </xsl:template>
</xsl:stylesheet> T:\ftemp>saxon gebhard.xml gebhard.xsl <?xml version="1.0" encoding="utf-8"?>162 T:\ftemp>
-- Public courses: sign up for one or both soon to reserve your seat! Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24 World-wide on-site corporate, government & user group XML training
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] sum of price * qty, without n, Charles Gebhard | Thread | [xsl] Re: sum of price * qty, witho, Dimitre Novatchev |
[xsl] sum of price * qty, without n, Charles Gebhard | Date | RE: [xsl] Empty object, Josh Canfield |
Month |