sort strings ending with numbers correctly

Discussion in 'XML' started by Rolf Kemper, Jan 20, 2005.

  1. Rolf Kemper

    Rolf Kemper Guest

    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
    Rolf Kemper, Jan 20, 2005
    #1
    1. Advertising

  2. 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
    David Carlisle, Jan 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claus
    Replies:
    9
    Views:
    17,018
    marcus
    Oct 6, 2004
  2. Navin
    Replies:
    1
    Views:
    668
    Ken Schaefer
    Sep 9, 2003
  3. GIMME
    Replies:
    5
    Views:
    177
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
  4. rader
    Replies:
    4
    Views:
    177
    Ernest Lergon
    May 7, 2005
  5. one man army

    Numbers to strings to numbers again

    one man army, Dec 28, 2005, in forum: Javascript
    Replies:
    6
    Views:
    132
    one man army
    Dec 30, 2005
Loading...

Share This Page