[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Subject: Sorting alpha numeric values
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|