Sign Up
Search
Options
search
Chat
Help
News
Log in
Not Logged in
Home
»
Boards
»
Stylus Studio Developer Network
»
XSLT Help and Discussion
»
Correct use of sum()
Topic
Topic Page
1
2
3
4
5
6
7
8
9
Prev Topic
Next Topic
next
Subject:
Correct use of sum()
Author:
steven matthews
Date:
06 Aug 2006 07:29 AM
Hi Again,
Can you help me with this one ?
The following xsl displays products bought for EACH customer invoice number. The output is sorted by invoice number:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:key name="invoiceid" match="/database/invoices/invoices_rec" use="invoiceNum"/>
<xsl:template match="/database">
<html>
<body>
<h2><center>All Customer Invoices</center></h2>
<xsl:for-each select="invoices/invoices_rec[ generate-id(.) = generate-id( key('invoiceid', invoiceNum)[1])]">
<xsl:sort select="invoiceNum" data-type="number" order="ascending"/>
<h3 style = "color: #0000ff">
<p>Ship to:</p>
<p>
<xsl:value-of select="contactName"/><br/>
<xsl:value-of select="shipToAddress"/><br/>
<xsl:value-of select="shipToCity"/><br/>
<xsl:value-of select="shipToState"/><br/>
<xsl:value-of select="shipToZip"/><br/></p>
<p><!-- display customer invoice details --></p>
<p>INVOICE NUMBER: <xsl:value-of select="invoiceNum"/></p>
<p>SALES DATE: <xsl:value-of select="salesDate"/><br/><br/></p>
</h3>
<table border="1" bgcolor="#F5DF91">
<tr bgcolor="#9acd32">
<th>Product ID</th>
<th>Product Name</th>
<th>Product Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Extended Price</th>
</tr>
<xsl:for-each select="key('invoiceid', invoiceNum)">
<tr>
<td><xsl:value-of select="ProductID"/></td>
<td><xsl:value-of select="ProductName"/></td>
<td><xsl:value-of select="ProductDescription"/></td>
<td><xsl:value-of select="Quantity"/></td>
<td><xsl:value-of select="UnitPrice"/></td>
<td><xsl:value-of select="ExtendedPrice"/></td>
</tr>
</xsl:for-each>
</table>
<p style = "color: #ff0000"><em>SubTotal:
<xsl:variable name="subtotal" select="Quantity * UnitPrice"/>
<xsl:text > EUROS </xsl:text>
<xsl:value-of select="$subtotal" />
</em></p><br/>
</xsl:for-each>
<br/>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Q Using this code:
<xsl:variable name="subtotal" select="Quantity * UnitPrice"/>
<xsl:text > EUROS </xsl:text>
<xsl:value-of select="$subtotal" />
I am trying to calculate the the total spent for EACH customer by adding together "Quantity * UnitPrice" for each product purchased.
I am unable to get this to work !
Any help would be appreciated, I have attached the xml source file
bigSteve
orders(1).xml
XML source
next
Subject:
Correct use of sum()
Author:
Ivan Pedruzzi
Date:
07 Aug 2006 03:13 PM
Steven,
It looks like that you already have the sub-totals for each item in the "ExtendedPrice" elements
The following should work
<em>
<xsl:text>SubTotal: EUROS </xsl:text>
<xsl:value-of select="sum(key('invoiceid',invoiceNum)/ExtendedPrice)"/>
</em>
Hope this helps
Ivan Pedruzzi
Stylus Studio Team
top
Subject:
Correct use of sum()
Author:
steven matthews
Date:
07 Aug 2006 05:10 PM
Hi Ivan,
Thanks a lot !
Once again you have solved my problem which means that I should get some sleep tonight, at least until another XSL problem comes along !
Cheers,
bigSteve
Topic Page
1
2
3
4
5
6
7
8
9
Prev Topic
Next Topic
Powered by
Stylus Studio
, the world's leading
XML IDE
for
XML
,
XSLT
,
XQuery
,
XML Schema
,
DTD
,
XPath
,
WSDL
,
XHTML
,
SQL/XML
, and
XML Mapping
!
Go to Conference:
Select Conference
Stylus Studio Feature Requests
Stylus Studio Technical Forum
Website Feedback
XSLT Help and Discussion
XQuery Help and Discussion
Stylus Studio FAQs
Stylus Studio Code Samples & Utilities
Stylus Studio Announcements
go
Log In Options
Username:
Password:
Site Map
|
Privacy Policy
|
Terms of Use
|
Trademarks
Stylus Scoop XML Newsletter:
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.