2008-09-08 7 views
12

が、私は、この指定されたXMLファイルが適用され、テンプレートを逆の順番で

<root> 
    <node>x</node> 
    <node>y</node> 
    <node>a</node> 
</root> 

を持っていると私は、次はあなたが

<xsl:template match="/"> 
    <xsl:apply-templates select="root/node"/> 
</xsl:template> 
<xsl:template match="node"> 
    <xsl:value-of select="."/> 
</xsl:template> 

答えて

30

Easy!

<xsl:template match="/"> 
    <xsl:apply-templates select="root/node"> 
     <xsl:sort select="position()" data-type="number" order="descending"/> 
    </xsl:apply-templates> 
</xsl:template> 

<xsl:template match="node"> 
    <xsl:value-of select="."/> 
</xsl:template> 
3

と同様のものを使用して

ayx 

を表示させたいと言いますxsl:sortを使ってこれを行うことができます。 data-type = "number"を設定することは重要です。そうしないと、位置は文字列としてソートされ、そのために終わります.10番目のノードは2番目のノードの前に考慮されます。

<xsl:template match="/"> 
    <xsl:apply-templates select="root/node"> 
     <xsl:sort 
      select="position()" 
      order="descending" 
      data-type="number"/> 
    </xsl:apply-templates> 
</xsl:template> 
<xsl:template match="node"> 
    <xsl:value-of select="."/> 
</xsl:template> 
関連する問題