How to do an XSL:for-each in reverse order

后端 未结 3 1619
一整个雨季
一整个雨季 2021-01-17 07:48

I am looking to reverse in XSL/FO a for-each loop.

for instance the xml


  
  
  

        
相关标签:
3条回答
  • 2021-01-17 08:19

    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>
    
    0 讨论(0)
  • 2021-01-17 08:29

    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>
    
    0 讨论(0)
  • 2021-01-17 08:30

    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)

    0 讨论(0)
提交回复
热议问题