2013-10-09 62 views
0

我被卡住了。我想要做的是爲我的單元格中的屬性分配一個數字。我通過調用一個模板並將一個參數傳遞給我所調用的模板來完成此操作。Param和XSLT應用模板

<xsl:call-template name="RowIdInitializer" > 
    <xsl:with-param name="i">1</xsl:with-param>   
    </xsl:call-template> 

我然後使用該PARAM並將其傳遞到應用模板作爲PARAM

<xsl:template name="RowIdInitializer"> 
<xsl:param name="i" /> 
    <xsl:apply-templates select="Data" mode="table" > 
    <xsl:with-param name="iThis" select="$i"/>    
    </xsl:apply-templates> 

<xsl:if test="@Exsist"> 
    <xsl:call-template name="RowIdInitializer"> 
    <xsl:with-param name="i" select="$i + 1">   
    </xsl:with-param>   
    </xsl:call-template> 
</xsl:if> 
</xsl:template> 

注意,我然後從內本身(遞歸)調用模板,並通過一個遞增的值我稱之爲模板的參數。嘗試模仿for循環,其中每個數據模式都具有Exist屬性(這可能稍後會出現問題,因爲第一次調用RowIdInitializer時會從一個級別調用,它可能會在Row節點查找Exist屬性,

<xsl:template match="Row"> 
    ..... some other stuff  
    <xsl:call-template name="RowIdInitializer" > 
    <xsl:with-param name="i">1</xsl:with-param>   
    </xsl:call-template> 
</xsl:template> 

但這不是指出它的問題)。傳遞給應用程序模板的參數是分配給屬性數據劃片頁面的位置。

<xsl:template select="Data" mode="table" > 
<xsl:param name="iThis" /> 
<td class="dataTableCell" onblur="cellEvent(event)" data-SwipePage ="$iThis">  
..otherstuff... 
</td> 

這就是問題所在。該值沒有被傳遞,字符串文字被賦值爲值。這樣,當我在瀏覽器的開發控制檯中檢查HTML時,我得到一個屬性data-SwipePage ="$iThis"爲所有爲每個行的子數據節點創建的td元素。我也試圖通過在一個公正的頭號這樣

<xsl:apply-templates select="Data" mode="table" > 
    <xsl:with-param name="iThis" select="1"/>    
    </xsl:apply-templates> 

<xsl:apply-templates select="Data" mode="table" > 
    <xsl:with-param name="iThis">1 </xsl:with-pam>    
    </xsl:apply-templates> 

我使用也試圖打破與-參數有關的所有<xsl:with-param這樣

<xsl:with-param name="iThis"> 
     <xsl:value-of select="$i"/> 
    </xsl:with-param> 

和字符串值仍在使用中。

回答

1

沒有充分評估你的代碼,有一個明顯的布布以上,其中你需要環繞你的變量$ iThis,用{和}如:

<xsl:template select="Data" mode="table" > 
<xsl:param name="iThis" /> 
<td class="dataTableCell" onblur="cellEvent(event)" data-SwipePage ="{$iThis}">  
..otherstuff... 
</td>