Wrox Programmer Forums
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2007, 08:59 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Soring

Hi all,

I would like to sort the element which has both alphabets and numbers.
How to sort the following elements based on Pin.

<PinNo><Pin>A17</Pin></PinNo>
<PinNo><Pin>A1</Pin></PinNo>
<PinNo><Pin>A3</Pin></PinNo>
<PinNo><Pin>A31</Pin></PinNo>

Note: Always the Pin starts with an alphabet..

Normal way of sorting gives me: A1, A17, A3, A31 which is wrong.. I need it like A1, A3, A17, A31

code:

<xsl:for-each select="PinNo">
  <xsl:sort select="Pin"/>
<xsl:value-of select="Pin"/>
</xsl:for-each>

Hope you will solve my problem

Regards,
Jack

 
Old January 12th, 2007, 09:10 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Saxon has an option for this:

<xsl:sort select="Pin" collation="http://saxon.sf.net/collation?alphanumeric=yes"

Further info at
http://www.saxonica.com/documentatio...collation.html

If the alpha part of the sort key is always one character, you can do

<xsl:sort select="substring(Pin,1,1)" data-type="text"/>
<xsl:sort select="substring(Pin,2)" data-type="number"/>

If the alpha part is always [A-Z], you could try

<xsl:sort select="translate(Pin,'0123456789','')" data-type="text"/>
<xsl:sort select="translate(Pin,'ABCDE...','')" data-type="number"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 12th, 2007, 09:41 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Mr.Kay,

Thanks a lot.. it did work.. Very very thankful to you..

Regards,
jack










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.