2008-09-08 38 views
12

nói rằng tôi có điều này tập tin xml choapply-templates theo thứ tự ngược

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

và tôi muốn những điều sau sẽ được hiển thị

ayx 

sử dụng một cái gì đó tương tự như

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

Trả lời

30

Dễ dàng!

<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

Bạn có thể làm điều này, bằng cách sử dụng xsl: sort. Điều quan trọng là đặt data-type = "number" vì khác, vị trí sẽ được sắp xếp dưới dạng chuỗi, kết thúc ở đó, nút thứ 10 sẽ được xem xét trước số thứ hai.

<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> 
Các vấn đề liên quan