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

Re: Sorting Index alphabetically

Subject: Re: Sorting Index alphabetically
From: Ragulf Pickaxe <ragulf.pickaxe@xxxxxxxxx>
Date: Thu, 24 Nov 2005 15:02:59 +0100
sort substring alphabetically
Hi Shailesh,

On 11/24/05, shailesh <shailesh@xxxxxxxxxxxx> wrote:
> How do I sort index alphabetically using xsl.


This is both a grouping and a sorting problem.
I would recommend looking through the various sites about grouping, for
example:
http://dpawson.co.uk/xsl/sect2/N4486.html#d5052e16 and
http://jenitennison.com/xslt/grouping/index.xml

A quick (untried) solution is here below.

<xsl:key name="first-letter" match="Keyword"
use="substring(translate(.,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRST
UVWXYZ'),1,1)"/>
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>

<!-- Iterate through each letter -->
<xsl:for-each
select="Keyword[generat-id(.)=generate-id(key('first-letter',substring(transl
ate(.,$lower,$upper),1,1)))]">
<xsl:sort select="substring(translate(.,$lower,$upper),1,1))"/>
<h2><xsl:value-of select="substring(translate(.,$lower,$upper),1,1))"/></h2>

<!-- Iterate through each word starting with current letter -->
<xsl:for-each
select="key('first-letter',substring(translate(.,$lower,$upper),1,1))">
<xsl:sort select="."/>
<xsl:value-of select="."/><br/>
</xsl:for-each>

</xsl:for-each>

I hope this helps you in the right direction.
Regards,
Ragulf Pickaxe :-)

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.