[英]Conversion from XSL-FO to PDF with Apache FOP starting from a XML file
I'm new to XSL-FO programming and I need help.我是 XSL-FO 编程的新手,我需要帮助。 I basically need to render a XSL-FO file into PDF with data from XML.
我基本上需要使用 XML 中的数据将 XSL-FO 文件渲染为 PDF。
But when I try, everything appears right int the PDF (background, manually entered text) but not data that should be read from XML.但是当我尝试时,一切都出现在 PDF(背景,手动输入的文本)中,但不是应该从 XML 读取的数据。
Notice that I tried only with the element "idShip".请注意,我仅尝试使用元素“idShip”。
My XML file:我的 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE shipment SYSTEM "C:\Users\informatica\Documents\workspace\PrintTest\shipment.dtd">
<?xml-stylesheet href="shipment_to_pdf.xsl" ?>
<shipment>
<idShip>111</idShip>
<fare></fare>
<to>
<name></name>
<surname></surname>
<address1></address1>
<address2></address2>
<zip></zip>
<city></city>
<country></country>
<email></email>
<phone></phone>
</to>
<from>
<name></name>
<surname></surname>
</from>
</shipment>
XSL: XSL:
<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 page-height="135mm"
page-width="216mm" margin-top="10mm" margin-left="20mm"
margin-right="20mm" margin-bottom="10mm" master-name="PageMaster">
<fo:region-body background-color="#EFAFAF"
margin-top="20mm" margin-left="10mm" margin-right="10mm"
margin-bottom="20mm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence initial-page-number="1"
master-reference="PageMaster">
<fo:flow flow-name="xsl-region-body">
<fo:block text-indent="1em" font-family="sans-serif"
font-size="20pt" font-weight="bold" background-color="#EEEEEE"
line-height="20mm">
//this should be the problem
<xsl:for-each select="shipment">
<xsl:value-of select="idShip" />
</xsl:for-each>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
PDF right now renders as a block with a red background, but no data from XML. PDF 现在呈现为具有红色背景的块,但没有来自 XML 的数据。
You are using a so-called simplified XSLT module ( XSLT 1.1 recommendation , XSLT 2.0 recommendation ) which is almost correct, it is only missing the xsl:version
attribute in the root element.您正在使用所谓的简化 XSLT 模块( XSLT 1.1 推荐、 XSLT 2.0 推荐),这几乎是正确的,它只是在根元素中缺少
xsl:version
属性。
Just add xsl:version="1.0"
(or 2.0
if you need the new features and your XSLT processor supports them) to the fo:root
element and you should get the expected result.只需将
xsl:version="1.0"
(或2.0
如果您需要新功能并且您的 XSLT 处理器支持它们)添加到fo:root
元素,您就会得到预期的结果。
Note that a simplified stylesheet has some limitations, as you cannot define parameters, global variables, functions (if using XSLT 2.0), keys and other templates.请注意,简化的样式表有一些限制,因为您不能定义参数、全局变量、函数(如果使用 XSLT 2.0)、键和其他模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.