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

RE: sorting on decimal

Subject: RE: sorting on decimal
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Mon, 18 May 2009 23:09:41 +0200
RE:  sorting on decimal
Without collations this is a XSLT 1.0 solution:
(restriction is that each single decimal number is less than 256)

$ cat data.xml
<data>
<elem number="3.9.10">a</elem>
<elem number="3.10.1">b</elem>
<elem number="3.9.11">c</elem>
<elem number="3.9.9">d</elem>>
</data>
$ java org.apache.xalan.xslt.Process -in data.xml -xsl dec-coll.xsl | tidy
-q -xml
<?xml version="1.0" encoding="utf-8"?>
<elem number="3.9.9">d</elem>
<elem number="3.9.10">a</elem>
<elem number="3.9.11">c</elem>
<elem number="3.10.1">b</elem>

$ cat dec-coll.xsl
<xsl:stylesheet version="1.0">
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:func="http://exslt.org/functions"
  xmlns:ns="namespace"
>
  <xsl:output method="xml" />

  <xsl:template match="/data">
    <xsl:for-each select="elem">
      <xsl:sort select="ns:dec-coll(@number)"/>
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </xsl:template>

<!-- generates hex sequence from decimal numbering, eg. 03090B from 3.9.11
-->
  <func:function name="ns:dec-coll">
    <xsl:param name="str" />
    <xsl:choose>
      <xsl:when test="contains($str,'.')">
        <func:result select="concat(ns:hex(substring-before($str, '.')),
                             ns:dec-coll(substring-after($str, '.')))" />
      </xsl:when>
      <xsl:otherwise>
        <func:result select="ns:hex($str)" />
      </xsl:otherwise>
    </xsl:choose>
  </func:function>

<!-- works fine for $num &lt; 256 -->
  <func:function name="ns:hex">
    <xsl:param name="num" />
    <func:result select="substring
('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223242
5262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B
4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717
2737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798
999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEB
FC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5
E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF',
                                   2*$num +1,2)"/>
  </func:function>

</xsl:stylesheet>>

$


Mit besten Gr|_en / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschdftsf|hrung: Erich Baier
Sitz der Gesellschaft: Bvblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



             Don Smith
             <dsmith_lockesmit
             h@xxxxxxxxx>                                               To
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
             05/16/2009 01:26                                           cc
             AM
                                                                   Subject
                                       RE:  sorting on decimal
             Please respond to
             xsl-list@xxxxxxxx
              lberrytech.com








Yes, that did the trick.

Thanks very much.

Don

--- On Fri, 5/15/09, Michael Kay <mike@xxxxxxxxxxxx> wrote:

> From: Michael Kay <mike@xxxxxxxxxxxx>
> Subject: RE:  sorting on decimal
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Friday, May 15, 2009, 5:12 PM
>
> Yes, if you're using Saxon then
>
> <xsl:sort select="@number"
> collation="http://saxon.sf.net/collation?alphanumeric=yes"/>
>
> should do the job.
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
>
> > -----Original Message-----
> > From: David Carlisle [mailto:davidc@xxxxxxxxx]
>
> > Sent: 15 May 2009 20:52
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re:  sorting on decimal
> >
> >
> > you could use a collation that split up the decimal
> ranges
> > (saxon has an alphanumeric collation that would
> probably do the job)
> >
> > http://www.saxonica.com/documentation/extensibility/collation.html
> >
> > David
> >
> >
> ______________________________________________________________
> > __________
> > The Numerical Algorithms Group Ltd is a company
> registered in
> > England and Wales with company number 1249803. The
> registered
> > office is:
> > Wilkinson House, Jordan Hill Road, Oxford OX2 8DR,
> United Kingdom.
> >
> > This e-mail has been scanned for all viruses by Star.
> The
> > service is powered by MessageLabs.
> >
> ______________________________________________________________
> > __________

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.