xslt showing a group of n xml nodes one at a time

后端 未结 1 1957
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 12:48

update:

This question has some little xsl code in it !

I\'m struggling with this problem for weeks (even months). I\'m rather beginner throu

相关标签:
1条回答
  • 2020-12-22 12:55

    Given:

    XML

    <group>
        <item> 01 </item>
        <item> 02 </item>
        <item> 03 </item>
        <item> 04 </item>
        <item> 05 </item>
        <item> 06 </item>
        <item> 07 </item>
        <item> 08 </item>
        <item> 09 </item>
        <item> 10 </item>
        <item> 11 </item>
        <item> 12 </item>
        <item> 13 </item>
        <item> 14 </item>
        <item> 15 </item>
        <item> 16 </item>
        <item> 17 </item>
        <item> 18 </item>
        <item> 19 </item>
        <item> 20 </item>
        <item> 21 </item>
        <item> 22 </item>
        <item> 23 </item>
        <item> 24 </item>
        <item> 25 </item>
        <item> 26 </item>
    </group>
    

    the following stylesheet:

    XSLT 1.0

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:param name="pageSize" select="5" />
    <xsl:param name="pageNumber" select="3" />
    
    <xsl:template match="/group">
        <html>
            <body>
                <div id="page{$pageNumber}">
                    <ul>
                        <xsl:variable name="start" select="$pageSize * ($pageNumber - 1) + 1" />
                        <xsl:for-each select="item[position() >= $start and position() &lt; $start + $pageSize]">     
                            <li>
                                <xsl:value-of select="."/>
                            </li>
                        </xsl:for-each>
                    </ul>
                </div>
            </body>
        </html>
    </xsl:template>
    
    </xsl:stylesheet>
    

    will return:

    Result

    <html>
        <body>
            <div id="page3">
                <ul>
                <li> 11 </li>
                <li> 12 </li>
                <li> 13 </li>
                <li> 14 </li>
                <li> 15 </li>
                </ul>
            </div>
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题