sort strings ending with numbers correctly

R

Rolf Kemper

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
 
D

David Carlisle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top