[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Eliminating Duplicate Elements

Subject: Re: Eliminating Duplicate Elements
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 14 Aug 2002 11:12:35 +0000
xsl eliminate duplicates
Antony,
<xsl:copy-of select="//fred[not(wilma/pebbles/text() = preceding::wilma/pebbles/text())]"/>
would do the job.


if you have a structure like the one you have given..
( i have added <students> as  root element..)

<?xml version="1.0"?>
<students>
<fred>
<wilma>
<pebbles> one </pebbles>
</wilma>
</fred>

<fred>
<wilma>
<pebbles> two </pebbles>
</wilma>
</fred>

<fred>
<wilma>
<pebbles> one </pebbles>
</wilma>
</fred>
</students>

and if you want to eliminate the duplicates and print
one,two ( the texts in pebbles)
instead of one,two, one

then the simplest way of doing this is..
<xsl:template match="/">
<xsl:for-each select="//pebbles[not(. = preceding::pebbles/text())]">
<xsl:value-of select="."/>
<xsl:if test="not(position()=last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
this would give one , two

refer the XSLT-Reference to know how to use the axis ( when to use preceding , preceding-sibling , following etc..)
Vasu
From: Antony.Tomasovic@xxxxxxxx
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Eliminating Duplicate Elements
Date: Wed, 14 Aug 2002 14:33:13 +1000

Hi,

I've read the archives about elimating duplicate elements
but still can't seem to get my head around the concept.

Can anyone, in as simple terms as possible, explain how
I can use XSL to turn the following XML:

<fred>
<wilma>
<pebbles> one </pebbles>
</wilma>
</fred>

<fred>
<wilma>
<pebbles> two </pebbles>
</wilma>
</fred>

<fred>
<wilma>
<pebbles> one </pebbles>
</wilma>
</fred>

to output as:

<fred>
<wilma>
<pebbles> one </pebbles>
</wilma>
</fred>

<fred>
<wilma>
<pebbles> two </pebbles>
</wilma>
</fred>

using <xsl:for-each> loops.

Thanks,
Antony









Antony Tomasovic


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list






_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.