xsl-list
[Top] [All Lists]

RE: Correctly sorting ID's

2003-01-21 11:26:45
Thank you to everyone for their replies this afternoon, esp. Jeni and
Steven who have given me a working solution to this annoying problem. 

Niki Dinsey

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Michael Kay
Sent: 21 January 2003 17:27
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com;
xsl-list-digest(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Correctly sorting ID's


In a transform, is it possible to correctly sort these poorly 
formed id's listed below

If you're prepared to write some recursive XSLT code to transform the
keys, you could achieve this by the technique of prefixing each numeric
component with a digit indicating its length. Thus 1 becomes 11, 10
becomes 210, 15 becomes 215, 109 becomes 3109. This will give you a key
that collates alphabetically.

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


Currently my standard sort:

<xsl:apply-templates>
      <xsl:sort select="node()/@id"/>
</xsl:apply-templates>

Returns this:

<someNode id="CM09.1"/>
<someNode id="CM09.1.5"/>
<someNode id="CM09.10"/>
<someNode id="CM09.10.10.3"/>
<someNode id="CM09.10.15"/>
<someNode id="CM09.18.2"/>
<someNode id="CM09.2"/>
<someNode id="CM09.2.2"/>
<someNode id="CM09.22"/>
<someNode id="CM09.22.1"/>

it's the old classic... 1 then 10 before 2 etc.

I really need them sorted like the following:

<someNode id="CM09.1"/>
<someNode id="CM09.1.5"/>
<someNode id="CM09.2"/>
<someNode id="CM09.2.2"/>
<someNode id="CM09.10"/>
<someNode id="CM09.10.10.3"/>
<someNode id="CM09.10.15"/>
<someNode id="CM09.18.2"/>
<someNode id="CM09.22"/>
<someNode id="CM09.22.1"/>

I'm looking now to see if I can work this out and I was 
wondering if anybody would be able to help me with the 
correct sort selection.

The only other issue to be aware of is that the dots can go 
on indefinitely and I don't know until runtime the highest 
number of dot's in the any one id will be.

If anybody could point me to a resource that deals with this 
I would be most grateful.

Regards,

Niki Dinsey



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



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



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



<Prev in Thread] Current Thread [Next in Thread>