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

RE: Subject: Sorting alpha numeric values

Subject: RE: Subject: Sorting alpha numeric values
From: David Neary <David@xxxxxxxxx>
Date: Fri, 9 May 2003 10:38:47 +0200
sorting alphanumeric data

De : Hugh Dixon [mailto:hugh.dixon@xxxxxxxxxxxxxx]
> 
> I want to sort a data set:
[snip]

> Into:
> A1
> A3George
> A21Fred
> A21Value
> B3Value
> B10Valuf
> 
> Sorting by the number and alpha prefix is essential, sorting by any
> suffix of numbers and alphas would be 'icing on the cake'.

Ah - but the same solution will work - use 3 sort keys.

1) initial alpha:

<xsl:sort select="substring(.,1,1)" data-type="text"/>

2) Numeric data (note: this translation assumes that there's no numeric data
in the trailing text - A12Bad12 will translate to 1212, which is not what
you want)

<xsl:sort
select="translate(.,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS
TUVWXYZ', '0123456789')" data-type="number")/>

3) Trailing alpha data (This one relies on the fact that since we've already
sorted on the first letter, we can include that data in the sort string
without changing the desired order).

<xsl:sort
select="translate(.,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012
3456789', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')"
data-type="text")/>

Et voilà, as they say here.

Cheers,
Dave.

 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.