Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2009, 06:08 PM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding XSLT Values with Matching Headings

Hello everyone. I literally love this site and the community, usually I can find problems by reading through your forums, but I haven't been able to find something to help me on my most recent problem. Any help? Thanks.


Here's a snippet of my XML file:

<data>

<transaction>
<transaction_details>
<name>Nickie</name>
<number>5</number>
</transaction_details>
</transaction>

<transaction>
<transaction_details>
<name>Chris</name>
<number>2</number>
</transaction_details>
</transaction>

<transaction>
<transaction_details>
<name>Nickie</name>
<number>5</number>
</transaction_details>
</transaction>

</data>
--------------------------------------------
What I'm trying to do is add the values of the people named Nickie, and get the number 10.

Is this possible?

<xsl:value-of select= ? or is it something else?

Thanks everyone and anyone who helps.
 
Old August 5th, 2009, 07:34 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

sum(transaction/transaction_details[name='Nickie']/number)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 5th, 2009, 07:59 PM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default That was a prompt reply, thanks

Thanks for that really prompt reply I appreciate it, seriously.

Anyways, I deal mainly with just HTML and CSS, but for this project I'm doing now needs me to branch out to a little more complicated and different things.
So, I'm still having problems...

------------------
The XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<data>

<transaction>
<transaction_details>
<name>Nickie</name>
<number>5</number>
</transaction_details>
</transaction>

<transaction>
<transaction_details>
<name>Chris</name>
<number>2</number>
</transaction_details>
</transaction>

<transaction>
<transaction_details>
<name>Nickie</name>
<number>5</number>
</transaction_details>
</transaction>

</data>
----------------------
The XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>RabbitPack.com</h2>
<table border="2">
<tr bgcolor="#3acd32">
<th>Nickie Total</th>
<th>Chris Total</th>
</tr>
<xsl:for-each select="data/transaction/transaction_details">
<tr>
<td><xsl:value-of select="sum(data/transaction/transaction_details[name='Nickie']/number)"/></td>
<td><xsl:value-of select="sum(data/transaction/transaction_details[name= 'Chris']/number)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
------------------------------
The Output: As a table

Nickie Total____Chris Total
0_________________0
0_________________0
0_________________0
---------------------------------
Okay, my XSLT is probably all over the place. I really just want to be able to add up and distinguish the total for each one Nickie and Chris. Help?
 
Old August 6th, 2009, 12:21 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Just discard <xsl:for-each select="data/transaction/transaction_details">.

Code:
...
<th>Nickie Total</th>
<th>Chris Total</th>
</tr>
<tr>
<td><xsl:value-of select="sum(data/transaction/transaction_details[name='Nickie']/number)"/></td>
<td><xsl:value-of select="sum(data/transaction/transaction_details[name= 'Chris']/number)"/></td>
</tr>
</table>
</body>
...
__________________
Rummy
 
Old August 6th, 2009, 05:02 AM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I love you? Probably

Thanks a million.





Similar Threads
Thread Thread Starter Forum Replies Last Post
adding up values in xslt northwind XSLT 21 February 17th, 2017 09:07 AM
Matching Values between two ranges hood8jmark Excel VBA 2 May 2nd, 2008 09:55 AM
two workbooks--matching values within kwik10z Excel VBA 0 November 29th, 2007 11:51 AM
Matching of attribute values gb XSLT 2 February 10th, 2004 04:12 AM
XSLT - First Time Matching a Template highlife XSLT 4 July 25th, 2003 07:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.