473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How can I sum the attribute node values....

Hi all,



I have the following XML file...

<root>

<row number="200" amount="2001" rate="0.234" quantity="5"/>

<row number="200" amount="1598" rate="0.234" quantity="52"/>

<row number="200" amount="6098" rate="0.234" quantity="91"/>

<row number="201" amount="2078" rate="0.422" quantity="5"/>

<row number="201" amount="8900" rate="0.422" quantity="53"/>

<row number="201" amount="2000" rate="0.422" quantity="73"/>

<row number="202" amount="2078" rate="0.000" quantity="5"/>

<row number="202" amount="8900" rate="0.000" quantity="53"/>

<row number="202" amount="2000" rate="0.000" quantity="73"/>

</root>



I want to get the following results...

I want to sum the 'amount*quantity' values for-each unique 'number' attribute. Like for "200", the sum should be equal to (2001*5 + 1598*52 + 6098*91). And for "201", the sum should be equal to (2078*5 + 8900*53 + 2000*73).
How can I get it working using XSLT 1.0?



Any ideas???
Oct 8 '07 #1
1 3691
jkmyoung
2,057 Expert 2GB
Using pure xslt 1.0, this isn't possible.

You would need to use a node-set extension function:
eg. msxsl:node-set
xmlns:msxsl="urn:schemas-microsoft-com:xslt"

Create a temporary variable with each of the products. say $products.

Then, use node-set on the variable to sum up the products. eg
<xsl:value-of select="sum(msxsl:node-set($products)/product)"/>


For the grouping, I would suggest using Muenchian grouping. See:
http://www.jenitennison.com/xslt/gro...muenchian.html
Oct 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
9
by: Iain | last post by:
I want to create an XML configuration file which might look like <REGION Name="Europe" WingDing="Blue"> <COUNTRY Name="UK" WingDing="white"> <TOWN Name="London" WingDing="Orange" /> </COUNTRY>...
4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
5
by: Aaron | last post by:
<xml> <test attrib1="hello" attrib2="world">textValue</test> </xml> I need some help getting the values of attrib1, attrib2 and the test tag. the output should be: hello world textValue
2
by: Bill Cohagan | last post by:
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications. I'm performing the validation via an xml document load() using a...
5
by: Soledad Vel | last post by:
Hi All, i write this code: var sliderwidth=100; var sliderheight = 100; var div1 = document.createElement('div'); div1.setAttribute('id','d5'); div1.setAttribute('style',...
5
by: patrin | last post by:
Hi All, given the source document: <?xml version="1.0" encoding="UTF-8"?> <root> <child> <test id="1" name="first child"/> </child> <child>
4
by: Hemal Pandya | last post by:
Hello, I am hoping this is a simple question with a straightforward solution. I do not understand xsl much, so I apologize in advance if I am asking a stupid question. Is it possible to write...
3
by: Eric Mahurin | last post by:
Is there a standard way to get a descriptor object for an arbitrary object attribute - independent of whether it uses the descriptor/ property protocol or not. I want some kind of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.