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]

RE: easy distinctive sorting?


Here is a stylesheet that was posted to the list a while back by Mark Volkman, which I think will help you .... the key is in testing whether the context node is equivalent to preceding-sibling.

Regards,
Kevin Albert

-----------------------------
<?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>
-----------------------------








-----Original Message-----
From: Hugo de Groot [mailto:H.de.Groot@xpuntx.nl]
Sent: Monday, July 31, 2000 9:32 AM
To: xsl-list@mulberrytech.com
Subject: easy distinctive sorting?


Hi,

One of my XSL stylesheets should output sorted elements, with an extra difficulty that there can be several identical elements, which should be included only once. If I would use SQL I'd probably use the statement 'SELECT DISTINCT'. I haven't found an easy way of doing this in XSL. Does anyone have a suggestion (apart from writing a custom template)?

Hugo De Groot
X punt X b.v. IT Services



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


 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]