paginator列表链接
问题描述:
我需要生成一个链接列表,作为最大值,我想要做的是paginator。paginator列表链接
例如:此变量提取最大链接数。
<xsl:variable name="countPages"
select="substring-after(substring-before(
//x:div[@class='navBarBottomText']/x:span, ')'), 'till ')" />
这种情况是:,该值是总的链路。
文件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" />
.....
缺少一些参数?谢谢。
答
你可以这样做你想要的方式 - 只需使用一个合适的变量引用:
更换:
<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>
+0
Ups ...错误sintaxis。抱歉。解决的其他问题是:concat('1'+ $ pos)。谢谢。 – 2013-03-24 15:15:06
+1
@AntonMM,NP。请参阅非递归解决方案(几分钟前添加),该解决方案更高效且更健壮。 – 2013-03-24 15:16:15
什么是您目前的结果是什么样子? paginator模板在哪里被调用? – JLRishe 2013-03-24 13:23:58
对不起,我编辑帖子,结果是'页面白色',错误:模板'paginator'未在此样式表中定义。 – 2013-03-24 14:35:47
AntonMM,请问编辑问题并提供应该在其上执行转换的源XML文档? – 2013-03-24 15:01:43