我正在使用Apache FOP 2.1在简单的Java应用程序中生成PDF文档。
当涉及生成具有动态行的表时,它总是以错误结束:
(Position des Fehlers unbekannt)org.apache.fop.fo.ValidationException: "fo:for-each" is not a valid child of "fo:table-row"! (Keine Kontextinformationen verfügbar)
我的xml输入如下:
<?xml version="1.0"?>
<invoicedata>
<invoice>
<positions>
<position>
<posOrder>1</posOrder>
<quantity>2</quantity>
</position>
<position>
<posOrder>2</posOrder>
<quantity>1</quantity>
</position>
</positions>
</invoice>
</invoicedata>
我的xsl fo模板看起来像:
<?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:template match="invoicedata">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="297mm" page-width="210mm"
margin-top="0.5cm" margin-bottom="0.5cm" margin-left="2cm" margin-right="2cm">
<fo:region-body region-name="xsl-region-body" margin-bottom="3.5cm" margin-top="5cm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body" font-size="10pt">
<xsl:if test="invoice/positions">
<fo:block>
<fo:table table-layout="fixed" width="100%" border-style="solid" border-width="1pt" >
<fo:table-column column-width="7%" border-style="solid" border-width="1pt" />
<fo:table-column column-width="8%" border-style="solid" border-width="1pt" />
<fo:table-header background-color="gray">
<fo:table-row>
<fo:table-cell border-style="solid" border-width="1pt" >
<fo:block text-align="center">Pos.</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="1pt" >
<fo:block text-align="center">Menge</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row>
<fo:for-each select="invoice/positions">
<fo:table-cell >
<fo:block text-align="right">
<xsl:value-of select="posOrder" />
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block text-align="right">
<xsl:value-of select="quantity" />
</fo:block>
</fo:table-cell>
</fo:for-each>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:if>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
所以,atm我不知道如何配置for-each元素来生成一个包含动态行的表。