18行动态表格生成
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- 定义传入的参数 -->
<xsl:param name="listSize"/>
<!-- 定义根节点的处理方式 -->
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm"
margin-top="1cm" margin-bottom="1cm" margin-left="2cm" margin-right="2cm">
<fo:region-body margin-top="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<!-- 调用递归模板开始生成表格 -->
<fo:block>
<fo:table>
<fo:table-body>
<!-- 调用递归模板生成对应行数的表格 -->
<xsl:call-template name="generateRows">
<xsl:with-param name="currentRow" select="1"/>
</xsl:call-template>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<!-- 定义递归模板处理每一行数据 -->
<xsl:template name="generateRows">
<!-- 传入的参数currentRow表示当前行号 -->
<xsl:param name="currentRow"/>
<!-- 结束条件:如果当前行号大于列表大小,则不再生成表格行 -->
<xsl:if test="$currentRow <= $listSize">
<!-- 判断是否需要新的页序列 -->
<xsl:if test="($currentRow - 1) mod 18 = 0">
<!-- 结束当前页序列,并开始新的页序列 -->
<xsl:if test="$currentRow > 1">
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</xsl:if>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:table>
<fo:table-body>
</xsl:if>
<!-- 输出当前行的表格行 -->
<fo:table-row>
<fo:table-cell border="solid black 1px">
<fo:block>Row <xsl:value-of select="$currentRow"/>, Column 1</fo:block>
</fo:table-cell>
</fo:table-row>
<!-- 递归调用自身处理下一行数据 -->
<xsl:call-template name="generateRows">
<xsl:with-param name="currentRow" select="$currentRow + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

浙公网安备 33010602011771号