xsl-list
[Top] [All Lists]

Re: Natural Sort

2006-01-25 07:40:27

I keep forgetting that the sort expression needn't be a single xpath in
xslt2, so in that case you don't need to use the tricky replace regexp
to add the zero, you can do what I had in mind really and use
format-number to express all numbers with teh same number of digits.

This version works up to 6 digits (and without the
restrictions on digit runs being close)

  <xsl:for-each select="server">
      <xsl:sort>
      <xsl:value-of>
      <xsl:analyze-string select="@dn" regex="[0-9]+">
       <xsl:matching-substring>
          <xsl:value-of select="format-number(number(.),'000000')"/>
       </xsl:matching-substring>
       <xsl:non-matching-substring>
         <xsl:value-of select="."/>
       </xsl:non-matching-substring>
      </xsl:analyze-string>
      </xsl:value-of>
      </xsl:sort>
      <xsl:copy-of select="."/>
    </xsl:for-each>
  

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>