xsl-list
[Top] [All Lists]

RE: Sorting alpha numeric values

2003-05-08 23:02:12
Use this template

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html" indent="yes" />     
  
<xsl:template match="/">
  <xsl:for-each select="./Root/Elem">
    <xsl:sort select="substring-after(@val,'A')" data-type="number"/>
    <xsl:value-of select="./@val"/>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Hope this helps you

-----Original Message-----
From: Hugh Dixon [mailto:hugh(_dot_)dixon(_at_)listech(_dot_)com(_dot_)au]
Sent: Friday, May 09, 2003 10:37 AM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sorting alpha numeric values


I have a data set:
<Root>
<Elem val = "A1"/>
<Elem val = "A2"/>
<Elem val = "A21"/>
<Elem val = "A3"/>
</Root>

And a template:

<xsl:template match="/">
  <xsl:for-each select="./Root/Elem">
    <xsl:sort select="@val"/>
    <xsl:value-of select="./@val"/>
  </xsl:for-each>
</xsl:template>

I was hoping to sort the Elems into
A1
A2
A3
A21

But I cannot get a hybrid alpha/numeric sort happening.  Is there some
setting I'm missing, or could someone suggest how I can do this.  The
ability to create a custom routine on which to compare the values would
be handy, although I suspect the performance could be an issue.

Thanks in Advance!!

Hugh Dixon


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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