473,809 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculate the sum of similar node value and put it into one node

1 New Member
QUESTION:

There is a xml node like
<icc>
<cricket>
<player>sachi n</player>
<score>15</score>
</cricket>
<cricket>
<player>dravi d</player>
<score>20</score>
</cricket>
<cricket>
<player>sachi n</player>
<score>6</score>
</cricket>
<cricket>
<player>sachi n</player>
<score>19</score>
</cricket>
<cricket>
<player>dhoni </player>
<score>26</score>
</cricket>
<cricket>
<player>dravi d</player>
<score>15</score>
</cricket>
</icc>

REQUIRED OUTPUT:

i want to make it as

<icc>
<cricket>
<player>sachi n</player>
<score>40</score>
</cricket>
<cricket>
<player>dravi d</player>
<score>35</score>
</cricket>
<cricket>
<player>dhoni </player>
<score>26</score>
</cricket>
</icc>

DESCRIPTION:

1.if player name same then add it's whole score and put it into one node as like
(sachin having score in first node is 15 + secode node is 6 + third node is 19 = total is 40).
(dravid having score in first node is 20 + secode node is 15 = total is 35).
(dhoni having total score = 26).
Jul 17 '07 #1
1 1965
jkmyoung
2,057 Recognized Expert Top Contributor
http://www.jenitenniso n.com/xslt/grouping/muenchian.html

Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="cricketsByPlayer" match="cricket" use="player"/>
  2.  
  3.  
  4. <xsl:for-each select="cricket[count(.|key('cricketsByPlayer', player)[1]) = 1]">
  5.     <xsl:copy>
  6.         <xsl:copy-of select="player"/>
  7.         <score>
  8.             <xsl:value-of select="sum(key('cricketsByPlayer', player)"/>
  9.         </score>
  10.     </xsl:copy>
  11. </xsl:for-each>
Jul 17 '07 #2

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

Similar topics

1
2049
by: Eric | last post by:
I am trying to figure out a good way to implement a XSLT transformation. Basically my goal is that I want to be able to ouput the following XML in a document: <chart type="pie" width="100" height="100"> <data label="Foo" value="12"/> <data label="Bar" value="15"/> ..... </chart>
3
3151
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function since they're not used anymore. But now, I used an <xsl:apply-templates/> and for some reason, it works in some situation but not in others. I didn't put the whole XSL file since it's quite big. Here's the part that bugs
4
3040
by: Alfred Taylor | last post by:
I essentially need a countif() function for xsl. Something to where I could do countif(node-set, condition). Rather than try to get too extreme, i decided to just write one for my countif() with the condition hardcoded. (this was also my first venture into creating "functions") Pseudo-code is essentially this: Look at the current node and check the condition. If the condition is true, call our function again with an incremented...
5
1778
by: Matt | last post by:
I need help with passing a generated node set from a style sheet into my customer msxsl extension. I have the following node set that I am creating: <xsl:variable name="sql"> <SQL> <StoredProc>spGetReconID</StoredProc> <Parms> <parm> <name>@tran</name> <value>956</value> </parm>
1
1795
by: Dica | last post by:
hi all first off, i'm not trying to cross post, but couldn't find this newsgroup earlier (got here from a recommendation on microsoft.public.vb, where i originally posted this question). anyhow, i'm just getting into .Net and am trying to parse a document, but not able to read the values for the nodes consistently. anybody know what i'm doing wrong? it seems that i'm able to console.writeLine the value of the node at the beginning of...
0
1715
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
3
1751
by: Carles Company Soler | last post by:
Hello, I want to calculate the value of an attribute. For example <rect x="2+3" y="12"and be <rect x="5" y="12">. Is it possible using XSLT? Thanks!
7
43958
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics object. 4. If string size is less than the size of the rectangle, we are done.
3
1293
by: gentsquash | last post by:
Inside of <script></script>, inside of <body></body>, what are the differences between document.body.className="mystyle"; and document.body.setAttribute("class", "mystyle"); ? (...assuming that a CSS "mystyle" has been defined.) ================================================================
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.