问题描述
我正在通过 Apache FOP 生成 PDF,现在一切进展顺利.
I'm generating a PDF through Apache FOP, and since now things are going pretty well.
现在我需要遍历一个列表并显示其中的每个元素,为此我使用命令 <xsl:for-each select="myObject/myList">
,但是当 FOP 开始解析 XML 时,我收到此错误:
Now I need to loop through a list and display every element in it and to achieve this I'm using the command <xsl:for-each select="myObject/myList">
, but when FOP begin to parse the XML I get this error:
2015-09-30 12:04:39,772 [http-nio-8080-exec-4] WARN org.apache.fop.apps.FOUserAgent - Unknown formatting object "{http://www.w3.org/1999/XSL/Transform}for-each" encountered (a child of fo:root}. (See position 9:45)
java.lang.ClassCastException: org.apache.fop.fo.UnknownXMLObj cannot be cast to org.apache.fop.fo.pagination.Root
at org.apache.fop.fo.pagination.AbstractPageSequence.getRoot(AbstractPageSequence.java:145)
at org.apache.fop.fo.pagination.PageSequence.startOfNode(PageSequence.java:111)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:337)
at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
[...]
这是我的 XML 的结构:
This is the structure of my XML:
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="1.5cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:for-each select="myObject/myList">
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body" font-size="9">
## SOME STUFF ARE WRITTEN HERE ##
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
我明白一个问题可能是 FOP 只需要 fo:
元素.如果这是正确的,我如何遍历我的列表?
I understood that a problem could be the fact that FOP only wants fo:
elements. And if this is correct, how can I loop over my list?
推荐答案
您需要 XSLT(或执行相同工作的东西)将您的 XML 转换为 FOP 理解的 FO 词汇表.
You need XSLT (or something that does the same job) to convert your XML into the FO vocabulary that FOP understands.
您的 xsl:for-each
将被 XSLT 处理器理解.请参阅 http://xmlgraphics.apache.org 上的 FOP 快速入门指南中的Hello World with FOP"/fop/quickstartguide.html 一个最小的例子.
Your xsl:for-each
will be understood by an XSLT processor. See 'Hello World with FOP' in the FOP Quick Start Guide at http://xmlgraphics.apache.org/fop/quickstartguide.html for a minimal example.
FOP 可以将 XSLT 转换作为其处理的一部分运行,但您也可以使用独立的 XSLT 处理器(例如 Saxon)来生成 FO 文件,然后您可以将其提供给 FOP.
FOP can run the XSLT transformation as part of its processing, but you can also use a standalone XSLT processor such as Saxon to produce an FO file that you can then feed to FOP.
这篇关于对于 FOP xml 中的每个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!