I am using an XSLT to sort a piece of XML such as:
<feed>
<entry>
<title>A To Z</title>
</entry>
<entry>
<title>Action</title>
</entry>
</feed>
The XSLT looks like:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="name" select="'title'" />
<xsl:param name="order" select="'ascending'" />
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="atom:feed">
<xsl:copy>
<xsl:apply-templates select="/atom:feed/*[not(self::atom:entry)]" />
<xsl:apply-templates select="/atom:feed/atom:entry">
<xsl:sort select="*[name() = $name]" order="{$order}" />
<xsl:sort select="atom:id" data-type="number" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I expect the values to come out in an order such as A To Z, then Action, but the result contains the opposite. It would look like the whitespace is being ignored as a value to sort by.
In XSLT 1.0 the sorting is implementation defined, so it is quite possible some implementations ignore space for sorting. Which implementation are you using?
I’d recommend something like:
<xsl:sort select="translate(*[name() = $name],' ','_')" order="{$order}" />
Might solve your problem (although again depends on how the implementation of XSLT you are using sorts ‘_’)