*
The moose likes XML and Related Technologies and the fly likes xsl processing question 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 "xsl processing question" Watch "xsl processing question" New topic
Author

xsl processing question

randy singh
Greenhorn

Joined: Sep 24, 2003
Posts: 1
I have an input xml that looks like following :
<mydoc>
<myelem>
<val>23</val>
<name>george</name>
</myelem>
<myelem>
<val>55</val>
<name>tim</name>
</myelem>
<myelem>
<val>23</val>
<name>george</name>
</myelem>
<mydoc>
I need to do the following :
1. Go through each myelem
2. if there are more than one myelem
3. if the "val" of the current myelem is equal to another "myelem" val ( there can be many nodes randomly interdispersed )
4. then add the val, and collapse the "equal" myelem's into one myelem
5. if not print out myelem it out as is
For example in the above case it will be :
<mydoc>
<myelem>
<name>george</name>
<val>46</val>
</myelem>
<myelem>
<name>tim</name>
<val>55</val>
</myelem>
<mydoc>
any pointers how to do this ? I am using xalan processor.
thanks
randi
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
The best way is to set up a key valued on concat of name and val. Pick up the unique key (in your case, name+val) and output each one.

Muenchian method


Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: xsl processing question
 
Similar Threads
dynamic iteration of href attribrute in html:link tag?
multibox - nullPointerException
Attribute precedance in elements
JDK DOM question
how to merge two documents in memory