Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Eliminate duplicates

Reply
Thread Tools

Eliminate duplicates

 
 
jose.jeria@gmail.com
Guest
Posts: n/a
 
      07-18-2005
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?

 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      07-18-2005


http://www.jenitennison.com/xslt/grouping/index.html

(duplicate elimination is a special case of grouping where you just use
teh first element of each group.)

David
 
Reply With Quote
 
 
 
 
Mukul Gandhi
Guest
Posts: n/a
 
      07-20-2005
Please try this XSL. The stylesheet uses identity template. Appropriate
person elements are eliminated.

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

<xslutput 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:erson/name)">
<xsl:copy-of select="." />
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
eliminate concurrent statement Aji VHDL 2 01-04-2006 04:45 PM
how to eliminate duplicates in a multimap? Tony Young C++ 3 04-14-2005 01:08 PM
Eliminate postback flicker WITHOUT smartnav ujjc001 ASP .Net 8 01-05-2005 12:53 PM
How can I eliminate "Glitch"? Jluis VHDL 5 05-12-2004 07:59 PM
DropDown List eliminate intermediate spaces Lucas Campos ASP .Net 11 11-11-2003 04:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57