## [xsl] Problem sorting alphabetically: all uppercase entries come first.

 Subject: [xsl] Problem sorting alphabetically: all uppercase entries come first. From: Matthew Zimmerman Date: Mon, 15 Dec 2003 17:29:40 -0500
Hi,

I have some XML code that looks like this:

```<index level1="Japan" level2="birth control clinics and leagues"/>
<index level1="China" level2="birth control clinics and leagues"/>
<index level1="population" level2="control of"/>
<index level1="population" level2="excess of"/>
<index level1="birth control" level2="opposition to"/>
<index level1="birth control" level2="publicity for"/>
<index level1="birth control" level2="movement"/>
<index level1="birth control" level2="class-based"/>
<index level1="family limitation"/>
<index level1="birth control" level2="war and"/>
<index level1="Sanger, Margaret" level2="autobiographical"/>
<index level1="Japan" level2="modernization of"/>
<index level1="censorship"/>```

The final output should look something like this in a web browser:

```• 	China, birth control clinics and leagues
• 	Japan, birth control clinics and leagues
• 	Japan, modernization of
• 	Sanger, Margaret, autobiographical
• 	birth control, class-based
• 	birth control, movement
• 	birth control, opposition to
• 	birth control, publicity for
• 	birth control, war and
• 	censorship
• 	family limitation
• 	population, control of
• 	population, excess of```

That is, it should be sorted alphabetically, and if the first level is the same, then it short sort by index level 2, and so on.

You can see it works quite well except that words starting with uppercase letters come first. I am guessing it is sorting by ASCII values.

You can see an on-the-fly transformation at: http://wilde.acs.its.nyu.edu/sanger_dev/documents/show.php? sangerDoc=101865.xml

This is the XSL I am using for sorting:

In the root template I include this: (this index appears as a footer in the HTML Page)

```<ul>
<xsl:sort data-type="text" select="@level1"/>
<xsl:sort data-type="text" select="@level2"/>
<xsl:sort data-type="text" select="@level3"/>
<xsl:sort data-type="text" select="@level4"/>
</xsl:apply-templates>
</ul>```

Then I have these templates:

```<xsl:template match="index">
<li>
<xsl:apply-templates select="@level1"/>
<xsl:apply-templates select="@level2"/>
<xsl:apply-templates select="@level3"/>
<xsl:apply-templates select="@level4"/>
</li>
</xsl:template>

<xsl:template match="@level1">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="@level2">
<xsl:text>, </xsl:text>
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="@level3">
<xsl:text>, </xsl:text>
<xsl:value-of select="."/>
</xsl:template>```

```<xsl:template match="@level4">
<xsl:text>, </xsl:text>
<xsl:value-of select="."/>
</xsl:template>```

I have feeling my code is a bit convaluted or some is redundant (but that is another issue). I was just concerned about the sorting issue. I think the issue is Sablotron. Their release notes indicate that this issue was to be fixed in version 1.0, but I am using 1.0 along with PHP. I tested this xml and xslt today with Marc Liyanage's testXSLT which allows you to test with 4 different processors. The sorting worked in Saxon, but not Sablotron, Libxslt, or Xalan-J. In these three it sorted the way I indicated above. I also tried Saxon from the command line and the sorting worked as well. Is my sorting code correct? Is this a known processor issue? If my code is OK I will just try to switch to Saxon, but right now the PHP XSLT extension only works with Sablotron.

Thanks

```MZ
_________________
Matthew Zimmerman
Humanities Computing Group, NYU
Tel: 212.998.3038
Fax: 212.995.4120```

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