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

Re: Correctly sorting ID's

Subject: Re: Correctly sorting ID's
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Jan 2003 17:18:49 +0000
sort xml nodes by id
Hi there Niki,

> In a transform, is it possible to correctly sort these poorly formed
> id's listed below

Tricky. I did have a recursive solution for you until I noticed that
just because there's an ID CM09.18.2 doesn't mean that there's an ID
CM09.18. This irregularity makes the task very difficult.

I think that I'd pick one of the following general approaches:

1. Decide that your stylesheet is only going to cope with IDs that
have 5 components; or 10 components; or however many seems to be a
reasonable maximum. You can always test the XML to make sure that this
assumption holds and generate an error if it doesn't. But this allows
you to do:

  <xsl:apply-templates select="someNode">
    <xsl:sort data-type="number"
      select="substring-before(
                substring-after(@id, '.'), '.')" />
    <xsl:sort data-type="number"
      select="substring-before(
                substring-after(
                  substring-after(@id, '.'), '.') '.')" />
    ...
  </xsl:apply-templates>

2. Create an extension function that can select the Nth component from
an ID. Then create a recursive template that groups and sorts the
nodes based on their Nth component.

3. Have a pre-processing phase that changes the IDs such that the
number in each component of the ID is formatted with an appropriate
number of leading zeros. You will then be able to sort the nodes by ID
using alphabetical sorting.

4. Generate the stylesheet dynamically based on the data, creating a
stylesheet that contains the appropriate number of sorts for the depth
of the IDs that you encounter in the XML.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.