• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Could I sum Nodes?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a useful set of pages about XSLT. Your particular problem is classified as "Grouping".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic