473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with recursive sum

I've been having some issues with recursive summing and have been
unsuccessful at getting some of the solutions I've seen online to work.
I'm hoping that perhaps somebody in the newsgroup will be able to shed
some light on the issue.

I have the following XML:

<departmentStor e>
<name>S-Mart</name>
<department>
<name>Electroni cs</name>
<section>
<name>Video Games</name>
<system>
<name>Xbox 360</name>
<manufacturer>M icrosoft</manufacturer>
<price>$399.9 9</price>
<gameLibrary>
<game>
<name>Call of Duty 3</name>
<genre>Shoote r</genre>
<publisher>Acti vision</publisher>
<developer>Trey arch</developer>
<price>$59.99 </price>
</game>
<game>
<name>Fight Night Round 3</name>
<genre>Sports </genre>
<publisher>Elec tronic Arts</publisher>
<developer>EA Chicago</developer>
<price>$59.99 </price>
</game>
<game>
<name>Rainbow Six Vegas</name>
<genre>Shoote r</genre>
<publisher>Ubis oft</publisher>
<developer>Ubis oft Montreal</developer>
<price>$59.99 </price>
</game>
<game>
<name>Viva Pinata</name>
<genre>Simulati on</genre>
<publisher>Micr osoft</publisher>
<developer>Rare </developer>
<price>$49.99 </price>
</game>
</gameLibrary>
</system>
</section>
</department>
</departmentStore >

departmentStore , department, section, system, and gameLibrary all have
more children nodes than what are shown.

What I want to do is get the sum of all video game prices for a
specific system and display it when applying the template that matches
"system."

Any help would be very much appreciated. Thanks!

Nathaniel

Dec 27 '06 #1
2 1632
The alMIGHTY N wrote:
I've been having some issues with recursive summing and have been
unsuccessful at getting some of the solutions I've seen online to work.
I'm hoping that perhaps somebody in the newsgroup will be able to shed
some light on the issue.

I have the following XML:

<departmentStor e>
<name>S-Mart</name>
<department>
<name>Electroni cs</name>
<section>
<name>Video Games</name>
<system>
<name>Xbox 360</name>
<manufacturer>M icrosoft</manufacturer>
<price>$399.9 9</price>
<gameLibrary>
<game>
<name>Call of Duty 3</name>
<genre>Shoote r</genre>
<publisher>Acti vision</publisher>
<developer>Trey arch</developer>
<price>$59.99 </price>
</game>
<game>
<name>Fight Night Round 3</name>
<genre>Sports </genre>
<publisher>Elec tronic Arts</publisher>
<developer>EA Chicago</developer>
<price>$59.99 </price>
</game>
<game>
<name>Rainbow Six Vegas</name>
<genre>Shoote r</genre>
<publisher>Ubis oft</publisher>
<developer>Ubis oft Montreal</developer>
<price>$59.99 </price>
</game>
<game>
<name>Viva Pinata</name>
<genre>Simulati on</genre>
<publisher>Micr osoft</publisher>
<developer>Rare </developer>
<price>$49.99 </price>
</game>
</gameLibrary>
</system>
</section>
</department>
</departmentStore >

departmentStore , department, section, system, and gameLibrary all have
more children nodes than what are shown.

What I want to do is get the sum of all video game prices for a
specific system and display it when applying the template that matches
"system."
Never store prices with the currency sign embedded, because they then
cease to be numbers and can't be manipulated easily in functions. Always
store the currency as an attribute of the price, using the standard
3-letter currency codes used by your bank (eg here possibly USD or CAD),
like <price currency="USD"> 49.99</price>
and only translate to a currency sign for purposes of display or print.
Then it's easy to write:

<xsl:template match="system">
<xsl:value-of select="sum(gam eLibrary/game/price)"/>
</xsl:template>

If the data is not yours (ie you get given it), either persuade the
originators to do it right, or pass it through a filter which removes
the currency symbol or rewrites the document to use an attribute.

Motto: get the data model right to begin with, and everything else
pretty much falls into place. Get the data model wrong, and your project
is hosed before you start.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Dec 27 '06 #2
This can easily be done with FXSL.

Search for:

transform-and-sum
Cheers,
Dimitre Novatchev

"The alMIGHTY N" <na******@yahoo .comwrote in message
news:11******** **************@ 79g2000cws.goog legroups.com...
I've been having some issues with recursive summing and have been
unsuccessful at getting some of the solutions I've seen online to work.
I'm hoping that perhaps somebody in the newsgroup will be able to shed
some light on the issue.

I have the following XML:

<departmentStor e>
<name>S-Mart</name>
<department>
<name>Electroni cs</name>
<section>
<name>Video Games</name>
<system>
<name>Xbox 360</name>
<manufacturer>M icrosoft</manufacturer>
<price>$399.9 9</price>
<gameLibrary>
<game>
<name>Call of Duty 3</name>
<genre>Shoote r</genre>
<publisher>Acti vision</publisher>
<developer>Trey arch</developer>
<price>$59.99 </price>
</game>
<game>
<name>Fight Night Round 3</name>
<genre>Sports </genre>
<publisher>Elec tronic Arts</publisher>
<developer>EA Chicago</developer>
<price>$59.99 </price>
</game>
<game>
<name>Rainbow Six Vegas</name>
<genre>Shoote r</genre>
<publisher>Ubis oft</publisher>
<developer>Ubis oft Montreal</developer>
<price>$59.99 </price>
</game>
<game>
<name>Viva Pinata</name>
<genre>Simulati on</genre>
<publisher>Micr osoft</publisher>
<developer>Rare </developer>
<price>$49.99 </price>
</game>
</gameLibrary>
</system>
</section>
</department>
</departmentStore >

departmentStore , department, section, system, and gameLibrary all have
more children nodes than what are shown.

What I want to do is get the sum of all video game prices for a
specific system and display it when applying the template that matches
"system."

Any help would be very much appreciated. Thanks!

Nathaniel

Dec 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
1649
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example : I wish to create two threads in my application, one thread (the subject) will increment a variable, and another thread (the controller) will print a message saying "i am waiting..." or someting like that, until the counter of the first thread...
2
2892
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display descending sequence of digits. I have not followed the instructions completely regarding the...
8
1418
by: ali | last post by:
Hi, I'm trying to work on a recursive function that will give me root valuefor a given number. What i mean by root value is, if given 13, the answer is 1+3 = 4. If given 65, the answer is 2, i.e, 6+5=11, and 1+1=2. The final answer is always less than 10. I've been able to work on the code, but i can get it to work for
0
1411
by: Patrick.O.Ige | last post by:
I have this code below. All its suppose to do is to EXPAND / COLLAPSE ALL of my treeview. But when i use ASP.NET WEbmatrix it all works fine .. But with VS.NET is says TreeNodeCollection not defined and TreeNode not defined!!!!!!!!!!!!!!arg!!!! How am i suppose to define it in VS.NET.. Any help appreciated!
0
1836
by: Michael L | last post by:
Hi Guys(I apologize for the lengty post - Im trying to explain it as best i can) I've been cracking my head on this one for the past 24+ hours and i have tried creating the function in ten different ways and none of the versions i've made works exactly as it should. I have an array called $PageArray which contains a sorted list of all pages in my application. Im trying to create a recursive function(It dosn't need to be recursive if...
1
1341
by: none | last post by:
I'm trying to create a recursive function to evaluate the expressions within a list. The function uses eval() to evaluate the list. Like a lisp interpreter but very limited. What I'm looking for is a function to recursively traverse the list and provide answers in place of lists, so that ... Example = , ] Becomes: Example = Becomes: Example = 7 *Functions are defined in the script
0
1960
by: champ1979 | last post by:
I wrote an algorithm to get all the relatives of a person in a family tree. I'm basically getting all the users from the DB and am doing the recursive logic in code, so that there is only 1 call made to the DB. However, I am trying to do the same thing within a stored procedure in SQL using recursive CTEs (I think the performance might be better) but I'm finding it really tough to craft the CTE. I would really appreciate if someone could...
4
1906
by: rumbylove | last post by:
Could I please have the solutions to the following problems 1. (4 points) Your friend has to write code to make sure that the parentheses in an arithmetic expression are balanced, i.e. for every left parenthesis there is a matching right parenthesis. She wants to use a tree to do this. You argue that if all you want to do is match parentheses, then a stack will work fine. How will you use a stack to do this? 2. (6 points) A palindrome is...
0
9673
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
9524
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
10449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.