I am looking to reverse in XSL/FO a for-each loop.
for instance the xml
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:sort is your friend ;
<xsl:for-each select="descendant-or-self::*/record">
<xsl:sort select="@id" order="descending" />
<xsl:value-of select="@id"/>
</xsl:for-each>
Yes, Alexander is right - forgot the data-type though:
<xsl:for-each select="descendant-or-self::*/record">
<xsl:sort select="@id" order="descending" data-type="number" />
<xsl:value-of select="@id"/>
</xsl:for-each>
(without that, you'll run into sorting problems with numbers over 9)