これは、要素名による昇順ソートの XSLT ソート エッジ ケースのフォローアップです。
その質問に記載されている回答を使用して、ほとんどの問題を解決できました。ただし、ソートが期待どおりに機能しない場合がまだあります。
これは私のソース XML です -
<Sources>
<name rank="">ABcoop / Jiji Commodities News (Japanese) !RSC!</name>
<name rank="">ABcoop Treasury & Company News (Japanese) !RSS!</name>
<name rank="">ABcoop Treasury News (Japanese) !RS!</name>
<name rank="">AB Corporate Finance News !RINVB!</name>
<name rank="">AB Insider !RITV!</name>
</Sources>
私のXSLT:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
default-collation="http://saxon.sf.net/collation?decomposition=full">
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="name">
<xsl:sort select="@rank" data-type="number"/>
<xsl:sort />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="name">
<name rank="{@rank}">
<xsl:copy-of select="text()"/>
<xsl:apply-templates select="name">
<xsl:sort select="@rank" data-type="number"/>
<xsl:sort />
</xsl:apply-templates>
</name>
</xsl:template>
</xsl:stylesheet>
ソートされた出力 (正しくない):
<?xml version="1.0" encoding="UTF-8"?>
<Sources>
<name rank="">ABcoop / Jiji Commodities News (Japanese) !RSC!</name>
<name rank="">ABcoop Treasury & Company News (Japanese) !RSS!</name>
<name rank="">ABcoop Treasury News (Japanese) !RS!</name>
<name rank="">AB Corporate Finance News !RINVB!</name>
<name rank="">AB Insider !RITV!</name>
</Sources>
期待される:
<?xml version="1.0" encoding="UTF-8"?>
<Sources>
<name rank="">AB Corporate Finance News !RINVB!</name>
<name rank="">AB Insider !RITV!</name>
<name rank="">ABcoop / Jiji Commodities News (Japanese) !RSC!</name>
<name rank="">ABcoop Treasury & Company News (Japanese) !RSS!</name>
<name rank="">ABcoop Treasury News (Japanese) !RS!</name>
</Sources>
編集: いくつかの回答で、デフォルトの照合 (default-collation 属性を削除) またはcollation = "http://www.w3.org/2005/xpath-functions/collation/codepoint"
xsl:sort 要素を使用することが示唆されたため、追加情報。
ただし、以前の投稿で指摘された問題は、Unicode コードポイントを照合 URI として使用すると、ソース XML の他の要素が正しくソートされないことです。
例えば、
<Sources>
<name>FX Buzz News Service !fxbuz!</name>
<name>French General News Service !fb!</name>
<name>French Money / Debt News Service !fg!</name>
</Sources>
Unicode コードポイント照合で正しくソートされていません。すべてのケースで機能する解決策を見つけようとしています。