aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "removing duplicate elements" Watch "removing duplicate elements" New topic
Author

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.

TIA
Radha Voodi
Greenhorn

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

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

Thanks,
Radha
Vijay Chouhan
Ranch Hand

Joined: Sep 01, 2005
Posts: 30
Hey thanks a ton Radha.. You've solved my problem.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: removing duplicate elements