2017-08-29 12 views
1

xsl:perform-sortを変数宣言内で使用しようとしていますが、効果がないようです。perform-sortは変数宣言内で使用できますか?

入力XML:

<root> 
    <section> 
     <seq>2</seq> 
    </section> 
    <section> 
     <seq>1</seq> 
    </section> 
</root> 

変換:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/*"> 

     <xsl:comment>using perform-sort</xsl:comment> 
     <xsl:variable name="vSections" as="element() *"> 
      <xsl:perform-sort select="section"> 
       <xsl:sort data-type="number" select="seq" /> 
      </xsl:perform-sort> 
     </xsl:variable> 

     <xsl:sequence select="$vSections/seq" /> 

     <xsl:comment>using for-each</xsl:comment> 
     <xsl:for-each select="section"> 
      <xsl:sort data-type="number" select="seq" /> 
      <xsl:sequence select="seq" /> 
     </xsl:for-each> 

    </xsl:template> 

</xsl:stylesheet> 

出力:

<!--using perform-sort--><seq>2</seq><seq>1</seq><!--using for-each--><seq>1</seq><seq>2</seq> 

を私はそれが含まれているsectionの要素をソートするためにvSections変数内xsl:perform-sortを期待していました。

私はxsl:perform-sortで間違っていることを理解しようとしています。 <xsl:sequence select="$vSections/seq" />

+0

興味深いを使用しています。 ''を実行するとどうなるかを確認してください。 –

答えて

1

あなたはドキュメント順(https://www.w3.org/TR/xpath-31/#id-path-operator)にソートするステップ/seqので、あなたは(私はそれは、XPath 3.0であると思います)<xsl:sequence select="$vSections!seq" />が必要になりますか<xsl:sequence select="for $s in $vSections return $s/seq" />

+1

2.0では、おそらく 'ドキュメントオーダー。 –

関連する問題