[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Correctly sorting ID's

Subject: RE: Correctly sorting ID's
From: "Kienle, Steven C [IT/0200]" <steven.c.kienle@xxxxxxxxxxxxx>
Date: Tue, 21 Jan 2003 11:30:09 -0500
10 before 2
To my eyes, this isn't a simple problem, mainly because you don't have
consistency in the format of the ID.  By that I mean you have CM09.1 and
CM09.10, which numerically are the same, but I think you mean something more
like CM09.01 and CM09.10.  Also, because you appear to allow for any number
of periods in the ID, it becomes an open ended sort, in effect.  If would be
best if you can control your input to force a specific format e.g.
'aa##.##.##.##' and force all parts to be fully qualified.

If you have no control over the input, you can do the sort like the
following:

<xsl:sort 
   select="substring-before(substring(concat(@id,'.0.0.0'), 2), '.')" 
   data-type="number"
/>
<xsl:sort 
   select="substring-before(substring-after(concat(@id,'.0.0.0'), '.'),
'.')" 
   data-type="number"
/>
<xsl:sort 
 
select="substring-before(substring-after(substring-after(concat(@id,'.0.0.0'
), '.'), '.'), '.')" 
   data-type="number"
/>

Where you have to add enough sort elements to match the reasonable maximum
number of sub-sections.  You also have to concat enough '.0.0...' to cover
the case where only the main section's number exists.  The substring-after
and substring-before functions allow you to step through the sub-section
numbers and add them to the sort.  This also ignores the preceeding
alphabetic code, but that can be added to the sort if it is important.

It doesn't look pretty, and certainly has limitations, but that will get the
work done.

	Steve

-----Original Message-----
From: Niki Dinsey - CSW [mailto:niki.dinsey@xxxxxxxxx]
Sent: Tuesday, January 21, 2003 10:24 AM
To: xsl-list-digest@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Correctly sorting ID's


Hi there list guru's, I have a question.

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

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.