[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Sorting alpha numeric values

Subject: RE: Sorting alpha numeric values
From: Jarkko Moilanen <Jarkko.Moilanen@xxxxxx>
Date: Fri, 9 May 2003 09:45:10 +0300 (EEST)
alphanumeric values
On Fri, 9 May 2003, Sundar Shanmugasundaram wrote:

OK, nice one Sundar. Lets take it a bit further. What if this XML would
contain also other @val's than A. For example:

<Root>
<Elem val = "B1"/>
<Elem val = "B2"/>
<Elem val = "B12"/>
<Elem val = "A1"/>
<Elem val = "A2"/>
<Elem val = "A21"/>
<Elem val = "A3"/>
</Root>

In this case your solution would not work. Instead the correct one
would be

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
  <xsl:for-each select="./Root/Elem">
    <xsl:sort select="substring(@val,1,1)"/>
    <xsl:sort select="substring(@val,'2')" data-type="number"/>
    <xsl:value-of select="./@val"/>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

This way the result would be:

A1 A2 A3 A21 B1 B2 B12

Cheers,
Jarkko

> 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.dixon@xxxxxxxxxxxxxx]
> Sent: Friday, May 09, 2003 10:37 AM
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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
>
>


****************************************************************
Jarkko Moilanen          "Erehtyminen on inhimillista,
Researcher                mutta todella suuret mokat
jm60697@xxxxxx            vaativat tietokoneen käyttöä."
www.uta.fi/~jm60697
GSM: +358 50 3766 927
****************************************************************
* ITCM | Information Technology and Crisis Management
* http://www.itcm.org
****************************************************************






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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.