XML:
<paginering>
<pagineringButtons>
<field name="pagineringButtonExcel" type="button"></field>
<field name="pagineringButtonPrint" type="button"></field>
</pagineringButtons>
<field name="pagineringPaginas" type="text"></field>
<field name="pagineringSelect" type="selectChosen">
<fieldOption id="10"><![CDATA[10]]></fieldOption>
<fieldOption id="100"><![CDATA[100]]></fieldOption>
<fieldOption id="20"><![CDATA[20]]></fieldOption>
<fieldOption id="50"><![CDATA[50]]></fieldOption>
<init id=""> </init></field>
</paginering>
XSL:
<ul class="paginering">
<li><a href="javascript:void(0)">Vorige</a></li>
<xsl:variable name="aantalRijen">
<xsl:value-of select="count(//row[@type='data'])" />
</xsl:variable>
<xsl:variable name="aantalPaginas">
<xsl:value-of select="ceiling($aantalRijen div 10)" />
</xsl:variable>
<li><xsl:value-of select="ceiling($aantalRijen div 10)" /></li>
<xsl:if test="not($num = $aantalPaginas)">
<xsl:call-template name="writePagenumbers">
<xsl:with-param name="num" select="$num + 1" />
</xsl:call-template>
</xsl:if>
<li><a href="javascript:void(0)">Volgende</a></li>
</ul>
<xsl:template name="writePagenumbers">
<xsl:param name="num" />
<li><xsl:value-of select="num"/></li>
</xsl:template>
'aantalPaginas'的值等于18。
通缉HTML:
<ul class="paginering">
<li><a href="javascript:void(0)">Vorige</a></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li><a href="javascript:void(0)">Volgende</a></li>
</ul>
如何从1到18进行良好的循环?我现在得到的结果是1'li',内部值为'18',1'li'没有内在值。我怎样才能做到这一点?
修改
<li>18</li>
来自有用循环。我只需要<li></li>
正确。
答案 0 :(得分:2)
假设num
变量最初设置为18,您可以在writePagenumbers
模板上执行递归调用
<xsl:template name="writePagenumbers">
<xsl:param name="num" />
<xsl:param name="current" select="1" />
<li><xsl:value-of select="$current"/></li>
<xsl:if test="$current < $num">
<xsl:call-template name="writePagenumbers">
<xsl:with-param name="num" select="$num" />
<xsl:with-param name="current" select="$current+ 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
如果您使用的是XSLT 2.0,则可以像这样编写
<xsl:template name="writePagenumbers">
<xsl:param name="num" />
<xsl:for-each select="1 to $num">
<pre><xsl:value-of select="."/></pre>
</xsl:for-each>
</xsl:template>