aspose file tools*
The moose likes XML and Related Technologies and the fly likes Could I sum Nodes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Could I sum Nodes?" Watch "Could I sum Nodes?" New topic
Author

Could I sum Nodes?

Alex Philippi
Greenhorn

Joined: Oct 05, 2007
Posts: 13
Hi, this is perhaps a weird question, but I have three nodes like these:

<position>1</position>
<quan>10</quan>
<position>2</position>
<quan>50</quan>
<position>1</position>
<quan>20</quan>


I am able to sum all fields with position 1, but I want only to display this position 1 one time in the transformed xml file. It should look like this:
<position>1</position>
<quan>30</quan>
<position>2</position>
<quan>50</quan>


But it look like this:
<position>1</position>
<quan>30</quan>
<position>2</position>
<quan>50</quan>
<position>1</position>
<quan>30</quan>

Is it possible to "say" in the xslt file to only print the position 1 only one time?

I hope you can help me

Best Regards
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I guess it is possible.


Q. How to ask an XSLT question?
A:
The easiest way to get answer real quick is post the original xml source, then post what you want to get the xml/html result. Of course, make it simple, and illustrate the point you want to solve only. Then your own approach which does not work as you desired. Many brain exercisers will solve your problem quickly. The answer will help others too.

* Do not throw the entire document here
* Do your own homework!
* Simplify the part you have problem with. Abstraction is a basic skill for programmers.
* Make both source and result well-formed XML.
* During this process, you might solve your own problem.
* If not, post a good question on a public forum.


Copied from
http://bobcat.webappcabaret.net/javachina/faq/xslt_01.htm#xslt_Q00
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Here is a useful set of pages about XSLT. Your particular problem is classified as "Grouping".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could I sum Nodes?