2016-01-13 41 views
0

我需要通過在XSL中調用模板來創建表格:FO 我希望能調用模板函數XSL fo動態創建表格

表模板

<xsl:template name="getTable"> 

使用FO創建表:表標籤,並呼籲柱模板並傳遞參數沒有列的

創建fo:body標籤並調用行模板並將no行作爲參數傳遞

</xsl:template> 

列模板例如

<xsl:template name="getcolumn"> 
</xsl:template> 
Row template 

呼叫的細胞的模板並通過無細胞參數的

</xsl:template> 

細胞模板

<xsl:template name="getCell"> 

呼叫的另一個模板

</xsl:template> 

我已經在XSL:FO中創建了一個表格。我可以通過下面的表格在XSL:fo中創建表格,但是我希望創建一個表格,因爲我需要根據輸入多次複製表格。

<fo:table xsl:use-attribute-sets="Table" > 
           <fo:table-column /> 
           <fo:table-column /> 
           <fo:table-body> 
            <fo:table-row > 
            <fo:table-cell > 


             <fo:block xsl:use-attribute-sets="JobTaskHeaderBackground"> 

             School1 
             </fo:block> 
            </fo:table-cell> 
            <fo:table-cell> 
            <fo:block> 
<xsl:call-template name="Required"> 
             <xsl:with-param name="ElementToCheck" select='m:SchoolName' /> 
</xsl:call-template> 
            </fo:block> 
           </fo:table-cell> 
           </fo:table-row> 
           </fo:table-body> 
           </fo:table> 
+0

目前還不清楚你打算如何填充多個表 - 假設你不希望它們具有相同的數據。 –

+0

您的'xsl:with-param'不允許在XSLT的這些點上使用。 –

+0

託尼你說得對,那是我把它放在呼叫模板標籤中的錯字。 – user1339913

回答

0

我需要複製了很多次,這取決於參數 如(NoOfTables)參數= 2

你可以有模板遞歸調用本身,如:

<xsl:template name="generate-tables"> 
    <xsl:param name="number-of-tables"/> 
    <xsl:param name="number-of-rows"/> 
    <xsl:param name="number-of-columns"/> 

    <xsl:if test="$number-of-tables > 1"> 

    <!-- code to generate a table --> 

    <!-- recursive call --> 
    <xsl:call-template name="generate-tables"> 
     <xsl:call-template name="repeat"> 
      <xsl:with-param name="number-of-tables" select="$number-of-tables - 1"/> 
      <xsl:with-param name="number-of-rows" select="$number-of-rows"/> 
      <xsl:with-param name="number-of-columns" select="$number-of-columns"/> 
     </xsl:call-template> 
    </xsl:if> 
</xsl:template> 

這假設您希望所有生成的表具有相同數量的行和列。

+0

謝謝邁克爾的回覆,但我如何傳遞一個參數來動態獲取'm:SchoolName'值(在單元格模板內)。學校名稱取自另一個模板**必填**。 – user1339913

+0

@ user1339913恐怕我不知道這是指什麼。你需要編輯你的問題並提供[mcve]。 –