This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: sorting data and removing the duplicates
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: sorting data and removing the duplicates
- From: "Mark Volkmann" <volkmann at inlink dot com>
- Date: Mon, 19 Jun 2000 06:33:50 -0500
- References: <4.3.1.0.20000619123157.00c6dd40@pop3.nl.net>
- Reply-To: xsl-list at mulberrytech dot com
----- Original Message -----
From: Ronald <ronald@salience.nl>
To: <xsl-list@mulberrytech.com>
Sent: Monday, June 19, 2000 5:39 AM
Subject: sorting data and removing the duplicates
> Hi there,
>
> I've encountered the following:
>
> I have a huge list of variables being set ( it's a xml file)
> and with XSLt i want to sort this file on alfabetical order
> and then remove the duplicates.
> The xml file sort of looks like this:
>
> <value><var>date1</var><date>01-01-1999</date></value>
> <value><var>date2</var><date>01-02-1999</date></value>
> <value><var>date3</var><date>01-01-1999</date></value>
> <value><var>date2</var><date>01-02-1999</date></value>
>
> I found that sorting this list was not so difficult, but removing the
> duplicates...erm...
> I dunno how to do that with XSLT.
> My current list looks like this:
>
> <value><var>date1</var><date>01-01-1999</date></value>
> <value><var>date2</var><date>01-02-1999</date></value>
> <value><var>date2</var><date>01-02-1999</date></value>
> <value><var>date3</var><date>01-01-1999</date></value>
>
> But I want something that looks like:
>
> <value><var>date1</var><date>01-01-1999</date></value>
> <value><var>date2</var><date>01-02-1999</date></value>
> <value><var>date3</var><date>01-01-1999</date></value>
>
> BTW:
> The content of the var. is enough to do a search on, F.E. date2 always
gets
> the same value.
This one should be in the archives because I asked it several months ago.
Here's the solution I was given.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h2>Original List</h2>
<xsl:apply-templates select="list"/>
<h2>Sorted List w/ No Duplicates</h2>
<xsl:apply-templates select="list" mode="sort-nodup"/>
</xsl:template>
<xsl:template match="list">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="list" mode="sort-nodup">
<xsl:apply-templates select="item[not(.=preceding-sibling::item)]">
<xsl:sort/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="item">
<div>
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list