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

RE: Sorting upper and lower case separately.

Subject: RE: Sorting upper and lower case separately.
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Wed, 20 Feb 2002 14:54:47 -0000
xsl lower case
>Is there any way to cause the sort command to sort all the upper case =
>first and then the lower case? I don't mean using the upper-case or =
>lower-case settings, because that just determines which order they are =
>in. But I want the following results:

This should work, although to me it looks a bit long-winded.

So, to sort this xml by case (upperfirst) and then by value:

<root>
<node>apple</node>
<node>Orange</node>
<node>bannana</node>
<node>Pear</node>
<node>peach</node>
<node>Monkey</node>
</root>

Output required:

Monkey
Orange
Pear
apple
bannana
peach


The XSL:

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

<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="hashes" select="'##########################'"/>
<xsl:variable name="lowercasenodes"
select="root/node[starts-with(translate(.,$lowercase,$hashes),'#')]"/>
<xsl:variable name="uppercasenodes"
select="root/node[starts-with(translate(.,$uppercase,$hashes),'#')]"/>

<xsl:template match="/">
  <xsl:apply-templates select="root/node" mode="upper">
    <xsl:sort select="."/>
  </xsl:apply-templates>
  <xsl:apply-templates select="root/node" mode="lower">
    <xsl:sort select="."/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="node" mode="lower">
  <xsl:if test=". = $lowercasenodes">
  <xsl:value-of select="."/><br/>
  </xsl:if>
</xsl:template>

<xsl:template match="node" mode="upper">
  <xsl:if test=". = $uppercasenodes">
    <xsl:value-of select="."/><br/>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

cheers

andrew

===


 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.