[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Summing a Calculation

Subject: RE: Summing a Calculation
From: bryan.s.schnabel@xxxxxxxxxxxxxx
Date: Thu, 21 Jun 2001 15:53:50 -0700
xsl sum calculation when
This works:

<xsl:template match="order">
    <b>
      <xsl:text>Total Price: </xsl:text>
      <xsl:value-of select="sum(item/price)"/>
    </b>
</xsl:template>

-----Original Message-----
From: Mark Swardstrom [mailto:mark@xxxxxxxxxx]
Sent: Thursday, June 21, 2001 11:55 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Summing a Calculation


I'm trying to get the sum of a purchase order, which seems simple, but I
can't find an easy solution.

Consider the following XML:

<order>
	<item>
		<id>1</id>
		<price>1.34</price>
		<quantity>4</quantity>
	</item>
	<item>
		<id>2</id>
		<price>5.77</price>
		<quantity>3</quantity>
	</item>
	<item>
		<id>5</id>
		<price>12.99</price>
		<quantity>1</quantity>
	</item>
</order>

I was trying to do something along these lines:

<xsl:template match="order">
	<xsl:apply-templates select="item"/>
	<b>Total price: <xsl:value-of select="sum(item/price *
item/quantity)"/></b>
</xsl:template>

To get a total amount for the entire order.

But that gives the following error.  

	Can not convert #NUMBER to a NodeList!

Before I go down the (seemingly too complex) recursive loop approach, I was
wondering if anyone else had another idea.

Thanks.

- Mark


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.