【问题标题】:XSL fo Create a Table DynamicallyXSL 用于动态创建表
【发布时间】:2016-04-18 08:05:34
【问题描述】:

我需要通过在 XSL:FO 中调用模板来创建表 例如 我希望调用模板函数

表格模板

<xsl:template name="getTable">

使用 fo:table 标签创建表并调用列模板并为列数传递参数

创建fo:body标签并调用行模板并将行号作为参数传递

 </xsl:template>

列模板例如

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

调用Cell模板并传递Cells参数的编号

 </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>

【问题讨论】:

  • 目前还不清楚您打算如何填充多个表 - 假设您不希望它们具有相同的数据。
  • 您的 xsl:with-param 在 XSLT 中的这些点上是不允许的。
  • 托尼,你说得对,是错字我已将其包含在调用模板标签中。

标签: xslt xsl-fo


【解决方案1】:

我需要根据参数多次复制它 例如(NoOfTables)param=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>

这是假设您希望所有生成的表都具有相同的行数和列数。

【讨论】:

  • 感谢 Michael 的回复,但是如何传递参数以动态获取 'm:SchoolName' 值(在单元格模板内)。学校名称是从另一个模板必需获得的。
  • @user1339913 恐怕我不知道这是指什么。您需要编辑您的问题并提供minimal reproducible example
猜你喜欢
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多