XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
steven matthewsSubject: Using the sum() function
Author: steven matthews
Date: 05 Aug 2006 09:40 AM
Hi There,

Further to my last query I have now downloaded and am using 'Stylus Studio 2006' IDE. What a great tool ...

My query refers to the following xsl file ....

<?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' version='1.0' encoding='UTF-8' indent='yes'/>

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
<th align="left">Country</th>
<th align="left">Company</th>
<th align="left">Price</th>
<th align="left">Year</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<xsl:if test="price &gt; 10">
<tr bgcolor="#eeeeff">
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="company"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="year"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<p>Total Cost:
<xsl:variable name="total" select="sum(//price)" />
<xsl:value-of select="$total" />
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Q. The statement "<xsl:if test="price &gt; 10">" will filter out those a price > 10. I would like to calculate the total cost of ONLY these items. The code currently calculates the cost of ALL items in the XML file. How can I do this ?

I have attached the xml file (cdcatalog.xml) required,

thanks,

Steven Matthews


Documentcdcatalog(1).xml

Postnext
Ivan PedruzziSubject: Using the sum() function
Author: Ivan Pedruzzi
Date: 05 Aug 2006 10:39 AM

format-number( sum( //price[. > 10] ), '##.#')

Postnext
steven matthewsSubject: Using the sum() function
Author: steven matthews
Date: 06 Aug 2006 07:31 AM
Thanks Ivan, that really works !

bigSteve

Posttop
(Deleted User) Subject: RE: Using the sum() function
Author: (Deleted User)
Date: 05 Aug 2006 03:55 PM
This is a grouping problem that is well documented at
http://www.dpawson.co.uk/xsl/sect2/sect21.html



Greg Alvord

615-221-7379

________________________________

From: stylus-studio-xslt Listmanager
[mailto:stylus-studio-xslt.listmanager@stylusstudio.com]
Sent: Saturday, August 05, 2006 8:56 AM
Subject: Using the sum() function



From: "steven matthews" <steven_matthews_uk@yahoo.co.uk>

Hi There,

Further to my last query I have now downloaded and am using 'Stylus
Studio 2006' IDE. What a great tool ...

My query refers to the following xsl file ....

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
<th align="left">Country</th>
<th align="left">Company</th>
<th align="left">Price</th>
<th align="left">Year</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<xsl:if test="price &gt; 10">
<tr bgcolor="#eeeeff">
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="company"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="year"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<p>Total Cost:
<xsl:variable name="total" select="sum(//price)" />
<xsl:value-of select="$total" />
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Q. The statement "<xsl:if test="price &gt; 10">" will filter out those a
price > 10. I would like to calculate the total cost of ONLY these
items. The code currently calculates the cost of ALL items in the XML
file. How can I do this ?

I have attached the xml file (cdcatalog.xml) required,

thanks,

Steven Matthews

--
Attachment: http://www.stylusstudio.com/SSDN/upload/cdcatalog%281%29.xml
(5KB)



--
To reply:stylus-studio-xslt.16247@stylusstudio.com
To start a new topic:stylus-studio-xslt@stylusstudio.com
To login:http://www.stylusstudio.com/SSDN/
To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! 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

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
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.