本文介绍了如何以相反的顺序执行 XSL:for-each的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在 XSL/FO 中反转 for-each 循环.
I am looking to reverse in XSL/FO a for-each loop.
例如 xml
<data>
<record id="1"/>
<record id="2"/>
<record id="3"/>
<record id="4"/>
<record id="5"/>
<record id="6"/>
</data>
使用 xsl
<xsl:for-each select="descendant-or-self::*/record">
<xsl:value-of select="@id"/>
</xsl:for-each>
我正在寻找输出 654321 而不是 123456
I am looking for the output 654321 and not 123456
这怎么可能?
推荐答案
使用 xsl:sort 不是按 @id
排序,而是按 position()
排序:
Use xsl:sort not for ordering by @id
but for ordering by position()
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/data">
<xsl:for-each select="descendant-or-self::*/record">
<xsl:sort select="position()" data-type="number" order="descending"/>
<xsl:value-of select="@id"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这篇关于如何以相反的顺序执行 XSL:for-each的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!