xsl:sort @lang attribute not considered when using AVT
Hi,
I have found what I believe is a bug when running xsltproc with a stylesheet that uses the xsl:sort
instruction and specifies language using a variable reference.
If I use this expression: <xsl:sort select="." lang="{$language}"/>
it seems to fall back to sorting by code points.
If I instead hard code the lang: <xsl:sort select="." lang="sv"/>
it works and the output is correctly sorted.
input
<?xml version="1.0" encoding="UTF-8"?>
<root lang="sv">
<element>Apa</element>
<element>Ål</element>
<element>Älg</element>
<element>Örn</element>
<element>Björn</element>
</root>
stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" encoding="UTF-8"/>
<xsl:variable name="language" select="'sv'"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<usingLiteral>
<xsl:apply-templates select="element">
<xsl:sort select="." lang="sv"/>
</xsl:apply-templates>
</usingLiteral>
<usingVariable>
<xsl:apply-templates select="element">
<xsl:sort select="." lang="{$language}"/>
</xsl:apply-templates>
</usingVariable>
</xsl:copy>
</xsl:template>
<xsl:template match="element">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
xsltproc stylesheet input
with locale sv_SE.utf8 installed
output running <?xml version="1.0" encoding="UTF-8"?>
<root>
<usingLiteral>
<element>Apa</element>
<element>Björn</element>
<element>Ål</element>
<element>Älg</element>
<element>Örn</element>
</usingLiteral>
<usingVariable>
<element>Apa</element>
<element>Björn</element>
<element>Älg</element>
<element>Ål</element>
<element>Örn</element>
</usingVariable>
</root>
As you can see the two sections are sorted differently. The first is in correct Swedish sort order. The second section seems to be sorted by code points which leads to 'Älg' switching positions with 'Ål'.
xsltproc version information
xsltproc --version
Using libxml 20904, libxslt 10132 and libexslt 820
xsltproc was compiled against libxml 20904, libxslt 10132 and libexslt 820
libxslt 10132 was compiled against libxml 20904
libexslt 820 was compiled against libxml 20904
Thank you in advance for looking into this.
Regards, Johan