对于FOP xml中的每个 [英] For each in FOP xml

查看:85
本文介绍了对于FOP xml中的每个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过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快速入门指南》中的使用FOP构成的Hello World"./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中的每个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆