XSLT sort question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samueln12
    New Member
    • Feb 2009
    • 28

    XSLT sort question

    Hi,

    I have the following content

    Code:
    <inline-graphic href="gkq255i1"/>
    <inline-graphic href="gkq255i2"/>
    <inline-graphic href="gkq255i3"/>
    <inline-graphic href="gkq255i100"/>
    <inline-graphic href="gkq255i10"/>
    <inline-graphic href="gkq255i11"/>
    <inline-graphic href="gkq255i99"/>
    <inline-graphic href="gkq255i101"/>
    when i am try to sort it i am getting the following output

    Code:
    <inline-graphic href="gkq255i1"/>
    <inline-graphic href="gkq255i2"/>
    <inline-graphic href="gkq255i3"/>
    <inline-graphic href="gkq255i10"/>
    <inline-graphic href="gkq255i100"/>
    <inline-graphic href="gkq255i101"/>
    <inline-graphic href="gkq255i11"/>
    <inline-graphic href="gkq255i99"/>
    but i required

    Code:
    <inline-graphic href="gkq255i1"/>
    <inline-graphic href="gkq255i2"/>
    <inline-graphic href="gkq255i3"/>
    <inline-graphic href="gkq255i10"/>
    <inline-graphic href="gkq255i11"/>
    <inline-graphic href="gkq255i99"/>
    <inline-graphic href="gkq255i100"/>
    <inline-graphic href="gkq255i101"/>
    How to do this in XSLT

    Thanks
    Sam
    Last edited by Dormilich; Apr 28 '10, 01:20 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if I read the specs right, XSLT does not implement a sorting algorithm itself (although it defines some basic options), which is left to the XSLT parser. currently I see no way to sort that this way.

    i could imagine it working, if you sort primarily by attribute length and then by text order, but well …

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      <xsl:sort select="substri ng-after(@href,'gk q255i')" data-type="number"/>
      If the string is not consistent, get the prefacing string into a variable, and replace 'gkq255i' with the variable.

      Comment

      • samueln12
        New Member
        • Feb 2009
        • 28

        #4
        Problem Solved

        Hi ALL,

        Thanks for all your support

        I finally fixed by the following method

        <xsl:sort select="transla te(child::inlin e-graphic/@href, 'abcdefghijklmn opqrstuvwxyz-', '00000000000000 0000000000000') " data-type="number"/>

        Thanks
        Sam

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          Thanks, interesting solution. Would probably not work for strings longer than 18 characters.

          Comment

          Working...