2013-03-24 123 views
1

我需要生成一個鏈接列表,作爲最大值,我想要做的是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" /> 
..... 

缺少一些參數?謝謝。

+0

什麼是您目前的結果是什麼樣子? paginator模板在哪裏被調用? – JLRishe 2013-03-24 13:23:58

+0

對不起,我編輯帖子,結果是'頁面白色',錯誤:模板'paginator'未在此樣式表中定義。 – 2013-03-24 14:35:47

+0

AntonMM,請問編輯問題並提供應該在其上執行轉換的源XML文檔? – 2013-03-24 15:01:43

回答

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> 
+0

Ups ...錯誤sintaxis。抱歉。解決的其他問題是:concat('1'+ $ pos)。謝謝。 – 2013-03-24 15:15:06

+1

@AntonMM,NP。請參閱非遞歸解決方案(幾分鐘前添加),該解決方案更高效且更健壯。 – 2013-03-24 15:16:15