[英]Conversion from XSL-FO to PDF with Apache FOP starting from a XML file
我是 XSL-FO 編程的新手,我需要幫助。 我基本上需要使用 XML 中的數據將 XSL-FO 文件渲染為 PDF。
但是當我嘗試時,一切都出現在 PDF(背景,手動輸入的文本)中,但不是應該從 XML 讀取的數據。
請注意,我僅嘗試使用元素“idShip”。
我的 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:
<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 現在呈現為具有紅色背景的塊,但沒有來自 XML 的數據。
您正在使用所謂的簡化 XSLT 模塊( XSLT 1.1 推薦、 XSLT 2.0 推薦),這幾乎是正確的,它只是在根元素中缺少xsl:version
屬性。
只需將xsl:version="1.0"
(或2.0
如果您需要新功能並且您的 XSLT 處理器支持它們)添加到fo:root
元素,您就會得到預期的結果。
請注意,簡化的樣式表有一些限制,因為您不能定義參數、全局變量、函數(如果使用 XSLT 2.0)、鍵和其他模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.