RE: [xsl] Sorting upper and lower case separately.

Subject: RE: [xsl] Sorting upper and lower case separately.
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Wed, 20 Feb 2002 14:54:47 -0000
>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