File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
XML and Related Technologies
Removing nodes based on a element
Joined: Oct 25, 2005
Dec 28, 2005 13:46:00
Need to remove duplicates in a xml file based on a element's value.
Just use the first node with the element in the resulting list;
Here is a sample xml:
<list> <book> <name>Title1</name> <author>Tom</author> </book> <book> <name>Title2</name> <author>Tom</author> </book> <book> <name>Title3</name> <author>Jim</author> </book> <book> <name>Title4</name> <author>Jim</author> </book> </list> -------------------------------------
The result needs to be:
In this case use the first occurance of the 'Author' element.
How can i accomplish this in xslt?
Any hints on which xsl functions i can use for this?
Thanks in Advance,
[ December 28, 2005: Message edited by: Rajiv Rangarajan ]
Joined: Oct 14, 2005
Dec 28, 2005 15:42:00
Consider the answer to the identical question posted on the Sun forum.
Joined: Oct 25, 2005
Dec 29, 2005 13:06:00
Yes, I did find the solution for the xml I posted
I have listed the same below for anyone interested.
<xsl:variable name="unique-list" select="//book[not(author=following::book/author)]"/> <xsl:template match="list"> <html><body><table border="1"> <xsl:for-each select="$unique-list"> <tr><td> <xsl:value-of select="name" /> </td><td> <xsl:value-of select="author" /> </td></tr> </xsl:for-each> </table></body></html> </xsl:template> </xsl:stylesheet>
I agree. Here's the link:
subject: Removing nodes based on a element
Passing Set<java.lang.Object> and List<java.lang.Object> in Axis 2.0
Testing web application for jump from Tomact to Jboss on load
How to implement getElementById() with Xerces using XML Schema?
XML One liners for the exam....
Castor: How to map list items within a "parent" list element?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014