我是新来的xsl,所以这可能是一个明显的答案。是否可以将XSL表中的行分隔为不同的页面序列?
我使用FOP在java中使用xml和xsl样式表创建表。该表可以有几千行(> 50,000),所以我想减少FOP的内存占用量以避免占用Java堆空间。
现在,我的xsl将整个<fo:table-body
>元素分组为一个单一的页面序列,因此在生成表格行时永远不会有任何回收存储器。是否有可能以某种方式将单独或成组的行分解成单独的页面序列?我知道我可以通过索引遍历元素(请参阅此stackoverflow回答:Xslt - iterate nodes in chunks),但我不认为<fo:page-sequence
>元素在<fo:table
>元素内是合法的。
如果无法拆分表中的行,是否有办法将行拆分成不同的表?
编辑:我想出这个从建议
输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<table title="sample">
<headers>
<column>title1</column>
<column>title2</column>
<column>title3</column>
<column>title4</column>
<column>title5</column>
<column>title6</column>
</headers>
<row>
<column>0</column>
<column>ABC</column>
<column>0</column>
<column>Claim Appeal</column>
<column>asldkjf98aet24</column>
<column>897123947623</column>
</row>
<row>
...
</row>
...
</table>
输入的xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no"
indent="yes"/>
<xsl:template match="table">
<xsl:variable name="startRow" select="0"/>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm"
page-width="22cm" margin-top="2cm" margin-bottom="2cm"
margin-left="1.5cm" margin-right="1.5cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:param name="startRow"/>
<fo:page-sequence>
<fo:table>
<xsl:if test="$startRow = 0">
<fo:table-header>
<fo:table-row font-weight="bold">
<xsl:apply-templates select="headers"/>
</fo:table-row>
</fo:table-header>
</xsl:if>
<xsl:foreach select="row[position() > $startRow &&
position() < 54]">
<!-- call row rendering template -->
<fo:table-body>
<xsl:apply-templates select="row"/>
</fo:table-body>
</xsl:foreach>
</fo:table>
</fo:page-sequence>
</fo:root>
<xsl:if test="$startRow < 100000">
<xsl:apply-templates select=".">
<xsl:with-param name="startRow" select="$startRow + 54"/>
</xsl:apply-templates>
</xsl:if>
<xsl:template match="headers">
<xsl:for-each select="column">
<fo:table-cell>
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</xsl:template>
<xsl:template match="row">
<fo:table-row>
<xsl:for-each select="column">
<fo:table-cell>
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:template>
</xsl:template>
</xsl:stylesheet>
有了这个,我上<page-sequence
错误>关于主引用的标签,但我已经用master-reference =“simpleA4”尝试过了,结果无济于事。是什么赋予了?
除了该语法错误之外,还有什么看起来不对?
你能否提供一个小例子来说明如何实现这一点?我似乎无法处理与他们里面的表设置循环的物流。 编辑:谢谢,现在我只需要弄清楚xslt的语法,让选择的伪代码进入工作状态。 – pclem12 2011-02-11 19:34:28