By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

sort strings ending with numbers correctly

P: n/a
Hi All,

I'm quite sure that somebody of you have already a solution for this:

ABC1
ABC12
ABC2
ABC21
ABC3

must be sorted like this

ABC1
ABC2
ABC3
ABC12
ABC21

the xsl:sort can't do it correctly, regardles of number or string data
type.

In priciple I would like to cut the numbers from the string and create
two sort tags. But as the split of the string is not that easy I have
no good solution.

Hope some one can help on this

Rolf
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

I'm not sure of your criterion, do you always have a fixed string ABC
and you want to do a numeric sort on the rest, or do you have
alpha-numeric strings and you want an alphabetic sort on the first part
and numeric on the second?

In the first case

<xsl:sort data-type="number" select="substring-after(.,'ABC')"/>

in the second case
<xsl:sort select="translate(.,'0123456789','')"/>
<xsl:sort data-type="number" select="substring-after(.,translate(.,'0123456789',''))"/>

David

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.