This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Eliminating Duplicate Elements


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@csiro.au
Reply-To: xsl-list@lists.mulberrytech.com
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]