File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes removing duplicate elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "removing duplicate elements" Watch "removing duplicate elements" New topic

removing duplicate elements

Vijay Chouhan
Ranch Hand

Joined: Sep 01, 2005
Posts: 30
Hi Ranchers,

I have some XML data of the following structure.

Now I need to process this data using XSL and ensure that the duplicate elements are output only once. Also the order of the elements should not be changed. The output for the above should look like.

Try as I hard I can, I am not able to make any headway. Will really appreciate any leads.

Radha Voodi

Joined: Jun 06, 2007
Posts: 1
Try this:

<xsl:template match="@*|node()">
<xsl:if test="not(node()) or not(preceding-sibling::node()[.=string(current()) and name()=name(current()])">
<xsl:apply-templates select="@*|node()"/>

Vijay Chouhan
Ranch Hand

Joined: Sep 01, 2005
Posts: 30
Hey thanks a ton Radha.. You've solved my problem.
I agree. Here's the link:
subject: removing duplicate elements
It's not a secret anymore!