Eliminate duplicates

J

jose.jeria

I have the following xml file:

<?xml version="1.0"?>
<people>
<person>
<name>Donald Duck</name>
</person>
<person>
<name>Goofy</name>
</person>
<person>
<name>Mickey Mouse</name>
</person>
<person>
<name>Donald Duck</name>
</person>
<!-- and so on -->
</people>


I want to eliminate any duplicate in this file. So Donald Duck would
only appear once. Note that Donald Duck would appear maximum 2 times in
the xml file, not more.

Is this possible to achieve with XSLT?
 
M

Mukul Gandhi

Please try this XSL. The stylesheet uses identity template. Appropriate
person elements are eliminated.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="xml" indent="yes" />

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>

<xsl:template match="person">
<xsl:if test="not(name = preceding-sibling::person/name)">
<xsl:copy-of select="." />
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top