列出paginator的链接

时间:2013-03-24 11:07:36

标签: xslt

我需要生成一个链接列表,因为我想要做的最大值是一个分页器。

示例:此变量提取最大链接数。

  <xsl:variable name="countPages" 
         select="substring-after(substring-before(
                     //x:div[@class='navBarBottomText']/x:span, ')'), 'till ' )" />

此案例为: 30 ,此值为链接总数。

文件XSLT:

  <xsl:template match="//x:div[@class='navBarBottomText']" >
    <xsl:call-template name="paginator"/>
  </xsl:template>
  <xsl:template name="paginator">
    <xsl:param name="pos" select="number(0)"/>
    <xsl:choose>
      <xsl:when test="not($pos >= countPages)">
        <link href="{concat('localhost/link=' + $pos)}" />
        <xsl:call-template name="paginator">
          <xsl:with-param name="pos" select="$pos + 1" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>

结果应该是这样的:

<link href="localhost/link=0" />
<link href="localhost/link=1" />
<link href="localhost/link=2" />
<link href="localhost/link=3" />
<link href="localhost/link=4" />
<link href="localhost/link=5" />
<link href="localhost/link=6" />
.....

缺少一些参数?感谢。

1 个答案:

答案 0 :(得分:1)

你可以按照你想要的方式做到这一点 - 只需使用适当的变量引用:

<强>替换

<xsl:when test="not($pos >= countPages)">

<强>与

<xsl:when test="not($pos >= $countPages)">

这里我假设变量$countPages是全局定义的(可见)。


非递归解决方案

<xsl:variable name="vDoc" select="document('')"/>

<xsl:for-each select=
  "($vDoc//node() | $vDoc//@* | $vDoc//namespace::*)[not(position() >= $countPages)]">

  <link href="localhost/link={position() -1}" />
</xsl:for-each>
相关问题