Eliminate duplicates

Discussion in 'XML' started by jose.jeria@gmail.com, Jul 18, 2005.

  1. Guest

    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?
     
    , Jul 18, 2005
    #1
    1. Advertising

  2. David Carlisle, Jul 18, 2005
    #2
    1. Advertising

  3. Mukul Gandhi Guest

    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
     
    Mukul Gandhi, Jul 20, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jluis
    Replies:
    5
    Views:
    1,052
    Ray Andraka
    May 12, 2004
  2. Aji
    Replies:
    2
    Views:
    2,200
  3. Lucas Campos

    DropDown List eliminate intermediate spaces

    Lucas Campos, Nov 4, 2003, in forum: ASP .Net
    Replies:
    11
    Views:
    769
    keyur shah
    Nov 11, 2003
  4. ujjc001
    Replies:
    8
    Views:
    4,516
    Jason
    Jan 5, 2005
  5. Tony Young
    Replies:
    3
    Views:
    484
    Maciej Pilichowski
    Apr 14, 2005
Loading...

Share This Page