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 April 14th, 2008, 11:29 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Suming value

Hi,

I've got a problem with suming up some value from my xml.

Here it is :

Code:
<output-objects>
    <output-object name="test">
      <attribute name="Currency">
        <text>EUR</text>
      </attribute>
      <attribute name="Total">
        <number>80000.08</number>
      </attribute>
    </output-object>
    <output-object name="test">
      <attribute name="Currency">
        <text>RON</text>

      </attribute>
      <attribute name="Total">
        <number>70000.07</number>
      </attribute>
    </output-object>
    <output-object name="test">
      <attribute name="Currency">
        <text>EUR</text>
      </attribute>
      <attribute name="Total">
        <number>60000.06</number>

      </attribute>
    </output-object>
</output-objects>
I'm trying to sum up the attribute 'Total' only when the Currency attribute is set to 'EUR'. So basicly, in this example, I want to sum : 80000.08 + 60000.06 only. I didn't manage to do it with solutions I've tried.

Hope that someone can help me...

Thanks in advance !

 
Old April 14th, 2008, 11:36 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is a template:
Code:
  <xsl:template match="/">
    <xsl:value-of select="sum(output-objects/output-object[attribute[@name = 'Currency']/text = 'EUR']/attribute[@name = 'Total']/number)"/>
  </xsl:template>
--
  Martin Honnen
  Microsoft MVP - XML
 
Old April 18th, 2008, 04:27 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot the answers
 
Old April 18th, 2008, 05:53 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Does it now work for you?
Note that my post has
[code]
<xsl:template match="/">
</code]
while your post has
Code:
<xsl:template match="output-objects">
meaning that you need to change the XPath expression:
Code:
<xsl:value-of select="sum(output-object[attribute[@name = 'Currency']/text = 'EUR']/attribute[@name = 'Total']/number)"/>
--
  Martin Honnen
  Microsoft MVP - XML









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