Subject: Re: [xsl] Correctly sorting ID's From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 21 Jan 2003 17:18:49 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Correctly sorting ID's, Niki Dinsey - CSW | Thread | RE: [xsl] Correctly sorting ID's, Michael Kay |
RE: [xsl] format-number, Michael Kay | Date | RE: [xsl] Correctly sorting ID's, Michael Kay |
Month |