Altova Mailing List Archives


Re: [xsl] Sorting problem...

From: cutlass <cutlass@----------->
To:
Date: 2/14/2001 12:55:00 AM
David M. Goudreau wrote:



I'm trying to sort some concatenated strings in a dropdown box in my XSL.
(I'm also sure there's a more compact way to write my XSL, frankly).  My XML
is:

<root sub_id="84">
	<folder name="c" cdate="2/13/01" id="f_49">
		<folder name="m" cdate="2/13/01" id="f_42" />
	</folder>
	<folder name="y" cdate="2/13/01" id="f_45" />
	<folder name="d" cdate="2/13/01" id="f_43" />
	<folder name="r" cdate="2/13/01" id="f_44" />
	<folder name="d" cdate="2/13/01" id="f_49">
		<folder name="t" cdate="2/13/01" id="f_42">
			<folder name="z" cdate="2/13/01" id="f_42">
		</folder>
	</folder>
</root>

I want my output to look alphabetical like the following:



-c
--c:m
-d
--d:t
---d:t:z
-r
-y

My XSL looks like this:

try using something like <xsl:sort select="@name"/> to handle your alpha 
sort first, the rest is recursion



-------------------------------



<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="root"> 



<xsl:apply-templates select="folder">
<xsl:sort lang="en" select="@name" data-type="text"/>
</xsl:apply-templates>


         
</xsl:template>



<xsl:template match="folder">
<xsl:value-of select="@name"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
-------------------------------

i leave the select / option tag stuff to u.



w3 org on sorting
http://www.w3.org/TR/xsl#sorting

xsl faq on sorting in general
http://www.dpawson.co.uk/xsl/N6461.html#N35304

,jim fuller




XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.