Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could I sum Nodes?

 
Alex Philippi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a useful set of pages about XSLT. Your particular problem is classified as "Grouping".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic