Java 无法使用Fop中的xsl fo从XML字符串生成PDF

Java 无法使用Fop中的xsl fo从XML字符串生成PDF,java,xslt,xsl-fo,Java,Xslt,Xsl Fo,我正在使用Fop生成PDF文件,我有xml和xsl源代码来转换xsl fo对象,但PDF文件显示为空白,请在这方面帮助我 这是我作为字符串的Xml响应: <enqResponse>…<cols><c>ID</c><c>DESCRIPTION</c></cols>….<r><c><cap>1111</cap><i>4</i></c>

我正在使用Fop生成PDF文件,我有xml和xsl源代码来转换xsl fo对象,但PDF文件显示为空白,请在这方面帮助我

这是我作为字符串的Xml响应:

 <enqResponse>…<cols><c>ID</c><c>DESCRIPTION</c></cols>….<r><c><cap>1111</cap><i>4</i></c><c><cap>Banks</cap></c></r>… </enqResponse>
…IDDESCRIPTION….11114银行…
这是我的Xslt文件:

 <?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" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
    <xsl:template match="enqResponse">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xml.apache.org/fop/extensions">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page" page-width="50in" page-height="80in">
          <fo:region-body  margin-top="1in" margin-bottom="1in" />
          <fo:region-before extent="2in"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="my-page">
          <fo:static-content flow-name="xsl-region-before">
               <fo:block font-size="12pt" font-weight="bold" text-align="center"><xsl:value-of select="title"/></fo:block>
          </fo:static-content>
          <fo:flow flow-name="xsl-region-body">
          <fo:block><xsl:apply-templates select="cols"/></fo:block>
          <fo:block><xsl:apply-templates select="r"/></fo:block>     
        </fo:flow>
        </fo:page-sequence>
    </fo:root>
    </xsl:template>
    <xsl:template match="cols">
                <fo:table table-layout="fixed" width="100%">
                <!--<fo:table-column column-width="2in"/>
                <fo:table-column column-width="4in"/>
                  --><fo:table-body>
                            <fo:table-row>
                             <xsl:for-each select="c">
                            <fo:table-cell>
                                        <fo:block><xsl:value-of select="."/></fo:block>
                            </fo:table-cell> 
                     </xsl:for-each>                
                    </fo:table-row>
              </fo:table-body>
                </fo:table>
    </xsl:template>

    <xsl:template match="r">
         <fo:table table-layout="fixed" width="100%">
                <!--<fo:table-column column-width="12in"/>
                <fo:table-column column-width="12in"/>
                     --><fo:table-body>
                     <fo:table-row>
                            <xsl:for-each select="c">
                                  <fo:table-cell>
                                  <fo:block><xsl:value-of select="cap"/></fo:block>
                            </fo:table-cell>
                     </xsl:for-each>  
                </fo:table-row>
                </fo:table-body>
                </fo:table>
    </xsl:template>
    </xsl:stylesheet>

当我将XML下载为PDF时,它会生成空白PDF文件,请给出您的建议,并让我知道XSLT文件中的任何错误。

其中,我有一个包含静态内容的xslt文件,它正确地显示为PDF格式,还有一个包含静态内容的xslt文件

    <?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" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
    <xsl:template match="enqResponse">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xml.apache.org/fop/extensions">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page">
          <fo:region-body margin="2in"/>
          <fo:region-before extent="1.0cm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="my-page">
          <fo:static-content flow-name="xsl-region-before" >
               <fo:block font-size="12pt" text-align="center">Page-1/1</fo:block>
          </fo:static-content>
          <fo:flow flow-name="xsl-region-body">
         <fo:block space-after="1.0cm">Welcome</fo:block>
          <fo:block>
                <fo:table table-layout="fixed" width="100%">
                       <fo:table-body>
                            <fo:table-row>
                      <fo:table-cell>
                            <fo:block>No</fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                            <fo:block>Name</fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                            <fo:block>Phone Number</fo:block>
                      </fo:table-cell>
                    </fo:table-row>

                    <fo:table-row>
                      <fo:table-cell>
                            <fo:block>Test1</fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                            <fo:block>Test2</fo:block>
                      </fo:table-cell>
                      <fo:table-cell>
                            <fo:block>Test3</fo:block>
                      </fo:table-cell>
                    </fo:table-row>
                       </fo:table-body>
                </fo:table>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
    </xsl:template>
    </xsl:stylesheet>

第1页,共1页
欢迎
不
名称
电话号码
测试1
测试2
测试3
请给出从给定xml字符串提取动态数据以生成PDF文件的解决方案……。

使用FOP或XEP(RenderX),我将获得一个包含生成文本的PDF。(但有些文字偏离了左边距。)


你确定你的PDF是空白的吗?由于您正在生成一个50英寸x 80英寸的页面(哇!),可能您就是看不到文本。

您使用的是哪个版本的XSL-FO处理器,以及运行它时的错误输出是什么?@Woody-处理器是FOP。标题和问题的第一句都提到了这一点。对不起,我弄错了,我没有看到在这两个地方使用了什么版本的FOP处理器。我想我的阅读能力不如你!由于0.2/0.9x版和1.0版之间的输出和处理发生了巨大的变化,因此它有点相关。