Re: [xsl] sorting strings (not default sorting) with xslt

Subject: Re: [xsl] sorting strings (not default sorting) with xslt
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Mar 2010 13:27:58 +0100
At 2010-03-18 13:12 +0100, Robby Pelssers wrote:
I would like to sort following strings ['BSS84/A2', 'BSS84/DG', 'BSS84'],

default sorting results in:

BSS84/A2 -> BSS84/DG -> BSS84

Not with the processor I am using (Saxon).


But the customer wants them sorted like

BSS84 -> BSS84/A2 -> BSS84/DG

So would I!


What's the easiest way to accomplish this?
Do I need to write a custom comparator function or can I use some <xsl:sort> shortcuts or is the only way to use collations?

Which processor are you using?


Below is an example ... what you want is ASCIIbetical and so the default sort collation of Unicode is fine.

I hope this helps.

. . . . . . . . . . . Ken

t:\ftemp>type robby.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each select="('BSS84/A2', 'BSS84/DG', 'BSS84')">
    <xsl:sort/>
    <xsl:value-of select="."/>
    <xsl:text>
</xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>xslt2 robby.xsl robby.xsl
BSS84
BSS84/A2
BSS84/DG

t:\ftemp>

--
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread