Xml ApacheFOP-空白PDF输出?

Xml ApacheFOP-空白PDF输出?,xml,apache,pdf,xsl-fo,apache-fop,Xml,Apache,Pdf,Xsl Fo,Apache Fop,我一直在尝试通过ApacheFop将XML文档转换为PDF, 但输出pdf为空 非常感谢您对发生这种情况的任何帮助 代码的执行似乎没有错误: C:\Users\dfh\Desktop\fop-0.20.5>fop-xml-DICENTIA_SDC_SN_1_224860.xml-xsl testx sl.xsl-pdf test2.pdf [信息]使用org.apache.xerces.parsers.SAXParser作为SAX2解析器 [信息]FOP 0.20.5 [信息]使用org.apa

我一直在尝试通过ApacheFop将XML文档转换为PDF, 但输出pdf为空

非常感谢您对发生这种情况的任何帮助

代码的执行似乎没有错误:

C:\Users\dfh\Desktop\fop-0.20.5>fop-xml-DICENTIA_SDC_SN_1_224860.xml-xsl testx sl.xsl-pdf test2.pdf [信息]使用org.apache.xerces.parsers.SAXParser作为SAX2解析器 [信息]FOP 0.20.5 [信息]使用org.apache.xerces.parsers.SAXParser作为SAX2解析器 [信息]正在构建格式化对象树 [信息]设置字体 [信息]文档解析完成,正在停止渲染器

XSL文件(testxsl):


你仍然得到一个空白PDF的主要原因是因为你的其他模板从未被应用。我对您的样式表做了一些更改(例如添加标识转换、更改
选择
、删除不必要的模板以及修复
文档编号
的拼写),并且我正在PDF上获得输出

XSL的修改版本:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output indent="yes"/>

  <xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:template>

  <xsl:template match="SDC_SN_1">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm">
          <fo:region-body margin-top="3cm"/>
          <fo:region-before extent="3cm"/>
          <fo:region-after extent="1.5cm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simple">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="General/Document_Number"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="Document_Number">
    <fo:block font-size="12pt" font-family="sans-serif" line-height="15pt" space-after.optimum="3pt" text-align="justify">
      <xsl:value-of select="."/>
    </fo:block>
  </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:template>

  <xsl:template match="SDC_SN_1">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
          <fo:region-body margin="1in" margin-top="1.5in"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="my-page">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="General">
    <fo:block font-weight="bold" text-decoration="underline" margin-top=".25in">General</fo:block>
    <fo:table margin-top=".25in" margin-bottom=".25in">
      <!-- border-style="solid" border-width="1pt" -->
      <fo:table-column column-width="25%"/>
      <fo:table-column column-width="75%"/>
      <fo:table-body>
        <fo:table-row>
          <xsl:apply-templates select="Document_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Order_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Sell_to_Customer/Name"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Customer_Order_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Customer_Order_Number2"/>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="General/Document_Number">
    <fo:table-cell>
      <fo:block>Document Number</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Order_Number">
    <fo:table-cell>
      <fo:block>Order Number</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="Sell_to_Customer/Name">
    <fo:table-cell>
      <fo:block>Name</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Customer_Order_Number">
    <fo:table-cell>
      <fo:block>Customer Reference</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Customer_Order_Number2">
    <fo:table-cell>
      <fo:block>Purchase Order</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="Shipping">
    <fo:block font-weight="bold" text-decoration="underline" margin-top=".25in">Shipping</fo:block>
    <fo:table margin-top=".25in" margin-bottom=".25in">
      <!-- border-style="solid" border-width="1pt" -->
      <fo:table-column column-width="25%"/>
      <fo:table-column column-width="75%"/>
      <fo:table-body>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Name"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Additional_Name_Info"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Contact_Person"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Address"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Additional_Address_Info"/>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Name">
    <fo:table-cell>
      <fo:block>Name</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Additional_Name_Info">
    <fo:table-cell>
      <fo:block>Name 2</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Contact_Person">
    <fo:table-cell>
      <fo:block>Contact</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Address">
    <fo:table-cell>
      <fo:block>Address</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Additional_Address_Info">
    <fo:table-cell>
      <fo:block>Address 2</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

</xsl:stylesheet>

我还编写了一个快速样式表,创建了“General”部分和“Shipping”部分(基于问题中最初的HTML输出)。不过,它使用的方法略有不同

我的XSL:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output indent="yes"/>

  <xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:template>

  <xsl:template match="SDC_SN_1">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm">
          <fo:region-body margin-top="3cm"/>
          <fo:region-before extent="3cm"/>
          <fo:region-after extent="1.5cm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simple">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="General/Document_Number"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="Document_Number">
    <fo:block font-size="12pt" font-family="sans-serif" line-height="15pt" space-after.optimum="3pt" text-align="justify">
      <xsl:value-of select="."/>
    </fo:block>
  </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:template>

  <xsl:template match="SDC_SN_1">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
          <fo:region-body margin="1in" margin-top="1.5in"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="my-page">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="General">
    <fo:block font-weight="bold" text-decoration="underline" margin-top=".25in">General</fo:block>
    <fo:table margin-top=".25in" margin-bottom=".25in">
      <!-- border-style="solid" border-width="1pt" -->
      <fo:table-column column-width="25%"/>
      <fo:table-column column-width="75%"/>
      <fo:table-body>
        <fo:table-row>
          <xsl:apply-templates select="Document_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Order_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Sell_to_Customer/Name"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Customer_Order_Number"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Customer_Order_Number2"/>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="General/Document_Number">
    <fo:table-cell>
      <fo:block>Document Number</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Order_Number">
    <fo:table-cell>
      <fo:block>Order Number</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="Sell_to_Customer/Name">
    <fo:table-cell>
      <fo:block>Name</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Customer_Order_Number">
    <fo:table-cell>
      <fo:block>Customer Reference</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="General/Customer_Order_Number2">
    <fo:table-cell>
      <fo:block>Purchase Order</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>
  </xsl:template>

  <xsl:template match="Shipping">
    <fo:block font-weight="bold" text-decoration="underline" margin-top=".25in">Shipping</fo:block>
    <fo:table margin-top=".25in" margin-bottom=".25in">
      <!-- border-style="solid" border-width="1pt" -->
      <fo:table-column column-width="25%"/>
      <fo:table-column column-width="75%"/>
      <fo:table-body>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Name"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Additional_Name_Info"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Contact_Person"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Address"/>
        </fo:table-row>
        <fo:table-row>
          <xsl:apply-templates select="Ship_to_Customer/Additional_Address_Info"/>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Name">
    <fo:table-cell>
      <fo:block>Name</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Additional_Name_Info">
    <fo:table-cell>
      <fo:block>Name 2</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Contact_Person">
    <fo:table-cell>
      <fo:block>Contact</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Address">
    <fo:table-cell>
      <fo:block>Address</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

  <xsl:template match="Ship_to_Customer/Additional_Address_Info">
    <fo:table-cell>
      <fo:block>Address 2</fo:block>
    </fo:table-cell>
    <fo:table-cell>
      <fo:block>: <xsl:value-of select="."/></fo:block>
    </fo:table-cell>    
  </xsl:template>

</xsl:stylesheet>

一般的
文件编号
: 
订单号
: 
名称
: 
客户参考
: 
采购订单
: 
航运
名称
: 
名称2
: 
接触
: 
地址
: 
地址2
: 

如果您在样式表方面需要任何其他帮助,或者您对我的样式表有任何疑问,请告诉我。

您正在将XML转换为HTML。您不需要将XML转换为xsl:fo吗?(除非FOP可以将HTML转换为PDF,我不知道?)在我的帖子中,将编辑过的样式表转换为xsl:fo样式表。但结果仍然是空白。知道为什么吗?谢谢//Daniel请看一下我的问题: