I’d like to group elements by the first letter, but some different letters should be considered equal: A and Ä (and a and ä) should all be the same.
Source:
<root>
<entry name="Aa" />
<entry name="Ab" />
<entry name="Äa" />
<entry name="Ac" />
<entry name="Ba" />
</root>
The transformation:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output indent="yes"/>
<xsl:template match="root">
<root>
<xsl:for-each-group select="entry" group-by="upper-case(substring(@name,1,1))">
<key><xsl:value-of select="current-grouping-key()"/></key>
</xsl:for-each-group>
</root>
</xsl:template>
</xsl:stylesheet>
The result now:
<root>
<key>A</key>
<key>Ä</key>
<key>B</key>
</root>
The result as I’d like it to have:
<root>
<key>A</key>
<key>B</key>
</root>
Where all entries except for “Bb” should be in the first group.
I assume the key to success is making the group-by() function correct to treat a,A,ä and Ä equal (this is true for some German sorting/ordering rules). But I have not found an xpath function that could handle that.
How about
translate(substring(@name,1,1), 'Ä', 'A')?