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

Re: Creating a padded sort key: easier from elt sequen

Subject: Re: Creating a padded sort key: easier from elt sequence or string?
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Fri, 28 Jul 2006 11:04:12 +0200
create a sort key
Florent Georges <darkman_spam@xxxxxxxx> wrote:

>  Yves Forkl wrote:
>
>  >> - As my dotted sequence [like "3.11.A.9"] can be of variable
>  >>   length, I need to determine the number of sort statements
>  >>   dynamically.
>
>
>  As you said the numbers are < 1000, you can easily create a
>  normalized sort string:
>
>      ~/xslt/tests> cat sort-keys.xsl
>      <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                     xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                     xmlns:my="my:sort-keys.xsl"
>                     version="2.0">
>
>        <xsl:output method="text"/>
>
>        <xsl:function name="my:normalise-sort-keys" as="xs:string">
>          <xsl:param name="keys" as="element()+"/>
>          <xsl:value-of separator="." select="
>              for $s in $keys/string(.) return
>                if ( matches($s, '[0-9]+') ) then
>                  format-number(number($s), '000')
>                else
>                  $s
>            "/>
>        </xsl:function>
>
>        <xsl:template match="/">
>          <xsl:for-each select="root/elt">
>            <xsl:sort select="my:normalise-sort-keys(sort_key_elt)"/>
>            <xsl:value-of select="@id"/>
>            <xsl:text>&#10;</xsl:text>
>          </xsl:for-each>
>        </xsl:template>
>
>      </xsl:transform>
>
>  [...]
>
>  If you choose a string instead of several elements as your keys, you
>  can adapt this with tokenize().

Thank you very much for this, the solution looks really neat in XSLT
2.0. How to achieve the same result in XSLT 1.1 where user-defined
functions are not generally available? (Not speaking of
processor-specific capabilities.)

My XSLT 1.1 approach would probably consist of generating the same
normalised sort key strings by first constructing a RTF from my sort
key components, then padding their string interpretations as above by means of format-number before concatenating them and passing the result to the sort statement via its select attribute.


Does that make sense to you?

One thing I'm not sure about is which "idiom" could help to implement
this idea. Can you give me a hint on this? (You don't need to bother
writing the full code.)

Yves

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.