This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: removing duplicate elements
 
It's not a secret anymore!