0
我正在使用Fop生成PDF文件,並且我有xml和xsl源來轉換xsl-fo對象,但PDF文件顯示爲空白請幫我在這...無法使用XPSL-fo在Fop中的XML字符串生成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>
,這是我的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文件親屬dly在此提供您的建議,並讓我知道id在xslt文件中有任何錯誤。
凡爲我與靜態內容的XSLT文件,並將其正確顯示PDF格式靜態內容
<?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>
XSLT文件請給予解決,從給定的XML字符串中提取數據的動態生成PDF文件...........
您正在使用哪種版本的XSL-FO處理器,以及運行時的錯誤輸出是什麼? – Woody 2012-04-26 09:16:21
@Woody - 處理器是FOP。它在標題和問題的第一句中提到。 – 2012-04-26 15:37:44
對不起 - 我的錯誤,我沒有看到哪個版本的FOP處理器在這些地方被使用 - 猜測我不像你那麼擅長閱讀!由於輸出和處理在版本0.2/0.9x和1.0之間大幅變化,這是相關的。 – Woody 2012-04-26 16:08:45