3

これは[質問]のフォローアップです: xsl multiple sort hierarchy

使用されている XSL は次のとおりです。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <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>

しかし、ランクは同じなのに、要素名(ASC)によるソートが正しくないケースがあります。

<name rank="100000">Motor Sports
   <name rank="100000">Motorcycle Racing [MOCY]
      <name rank="100000">Motocross [MOCR]</name>
      <name rank="100000">Speedway [SPEE]</name></name>
   <name rank="100000">Motor Racing [MORA]
      <name rank="100000">Formula 1 [FO1]</name>
   </name>
</name>

この場合、「Motor Racing」は「Motorcycle Racing」の上にあるはずです。これを理解するのを手伝ってもらえますか?私は両方を追加しようとしました

<xsl:sort select="text()" order="ascending"/>

<xsl:sort select="name" order="ascending"/>

<xsl:sort select="text()" order="ascending"/>

しかし、それはうまくいきませんでした。

ANSWER: @MichaelKay の回答に感謝します。私がこれを解決した方法は、XSLT プロセッサを Saxon に変更し、default-collat​​ion="http://saxon.sf.net/collat​​ion?decomposition=full" を使用することでした。

4

1 に答える 1

2

You say

"Motor Racing" should have been above "Motorcycle Racing"

XSLT does not define detailed collation rules. This is probably a collation in which spaces are ignored. Some people collate that way, others don't. Check the documentation for your XSLT processor, there may be a way of influencing the collation it uses.

Alternatively, you may be able to get the desired effect using something like

<xsl:sort select="translate(xxx, ' ', '-')"/>
于 2012-10-24T17:50:51.647 に答える