Re: [xsl] Sorting with Different Sort Keys

Subject: Re: [xsl] Sorting with Different Sort Keys
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Fri, 19 Oct 2007 16:22:26 +0800
On 10 19, 07, at 3:51 PM, Abel Braaksma wrote:

Michael Kay wrote:
Start by defining what you want to achieve a little bit more precisely.
Where do "Seite 99", "99", "Page 12" and "pink rabbit" fit in your desired
collating sequence?

Now that we're at it, I'm also wondering... how does "Seite 120", "seite 120", "SEITE 120", "Seite 0120", "seite 0012", " seite120" and "Seite 12000" fit in (note the extra or missing spaces and zeroes)?

Nodes with the string 'seite' must come first before those that do not have it. Those with seite are sorted according to the numeric value after it.


I tried using this function to get the sorting key:

<xsl:function name="ati:sort.key" as="node()">
<xsl:param name="node" as="element()"/>
<xsl:variable name="node.value" as="xs:string" select="replace (normalize-space($node), '[\n], '')"/>
<key>
<key1><xsl:sequence select="replace($node.value, '^(S\. \d+).*|(.+) $', '$1')"/></key1>
<key2><xsl:sequence select="replace($node.value, '^(S\. \d+).*|(.+) $', '$2')"/></key2>
</key>
</xsl:function>


Then using the following sort instructions:

<xsl:sort select="replace((ati:sort.key.nr(head))/key1, '[\D]', '')" data-type="number"/>
<xsl:sort select="replace((ati:sort.key.nr(head))/key2, '[\D]', '')" data-type="number"/>


-- Jeff

Current Thread