通过 xsl-fo 将 xml/html 表转换为 pdf
我正在研究 xslt 和 xsl-fo 代码以分别转换为 html 和 pdf。
在我的源 xml 中,我有一个表,可以直接复制该表以进行 html 输出。
<text>
<table border='1'>
<thead>
<tr><th>Problem</th><th>Date</th><th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cholecystitis</td><td>9/28/2002 - 6/2003</td>
<td>Resolved</td>
<td>Surgery postponed until after delivery</td>
</tr>
<tr>
<td>Pregnancy</td><td>7/2001 - 4/22/2002</td>
<td>Resolved</td>
<td>Prior history of miscarraige</td>
</tr>
<tr><td>Ankle Sprain</td><td>3/28/2005</td>
<td>Current</td>
<td>Slipped on ice and fell</td>
</tr>
</tbody>
</table>
</text>
我只是用它来复制节点的内容:
<xsl:copy-of select="."/>
我想这适用于 xslt 到 html 的转换,因为浏览器可以直接解释它。但对于我的 pdf,我想我必须使用完全不同的 xsl-fo。我知道在 xsl-fo 中我必须使用:
<fo:table>
但是,是否有一种“标准”方法来格式化此表以便能够将其用于我的 pdf 生成? pdf 的 xsl:copy 生成一行,其中包含所有剥离的值,但没有表格。
谢谢你!
=======================================
编辑
我想做的是编写一些 xslt 代码“解析”嵌入在我的源 xml 文件中的表以生成如下内容:
<fo:table table-layout="fixed" width="100%">
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
something
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
something
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
这是要走的路吗?!表格非常标准,我认为 html 表格可以轻松转换为 xslt/xsl-fo。
I'm working on a xslt and xsl-fo code to convert to html and pdf respectively.
In my source xml I have a table which I can copy directly for html output.
<text>
<table border='1'>
<thead>
<tr><th>Problem</th><th>Date</th><th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cholecystitis</td><td>9/28/2002 - 6/2003</td>
<td>Resolved</td>
<td>Surgery postponed until after delivery</td>
</tr>
<tr>
<td>Pregnancy</td><td>7/2001 - 4/22/2002</td>
<td>Resolved</td>
<td>Prior history of miscarraige</td>
</tr>
<tr><td>Ankle Sprain</td><td>3/28/2005</td>
<td>Current</td>
<td>Slipped on ice and fell</td>
</tr>
</tbody>
</table>
</text>
I just use this to copy the content for node:
<xsl:copy-of select="."/>
I suppose this works for the xslt convertion to html since the browser can interpret this directly. But for my pdf I suppose I have to use xsl-fo which is completely different. I know in xsl-fo I have to use:
<fo:table>
But, is there a "standard" way to format this table to be able to use it for my pdf generation? The xsl:copy for the pdf produces a single line with all the stripped values but no table.
Thank you!
=====================================
EDIT
What I'm trying to do is to code some xslt to "parse" the table embeded in my source xml files to generate something like this:
<fo:table table-layout="fixed" width="100%">
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
something
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
something
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
Is it the way to go?! Tables are pretty standard, I thought html table could be easily transformed to xslt/xsl-fo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,
为了解决我的问题,我找到了一篇 IBM 文章,准确地解释了我想要做的事情:
“HTML 到格式化对象 (FO) 转换指南”
http://www.ibm .com/developerworks/library/x-xslfo2app/#table
这非常简单,但您需要有经验才能完成此任务...我不太感谢 IBM。
So,
To solve my problem I found an IBM article explaining exactly what I was trying to do:
"HTML to Formatting Objects (FO) conversion guide"
http://www.ibm.com/developerworks/library/x-xslfo2app/#table
It is pretty straightforward but you need to be experienced to pull this off... I'm not so thank you IBM.
你走在正确的轨道上。是的,您必须将 HTML 元素转换为 XSL-FO 元素。 XSL-FO 引擎读取 XSL-FO 以了解如何呈现它,因此仅将 HTML 元素(绑定到 HTML 命名空间或没有命名空间)复制到 XSL-FO 文件中是行不通的。
看看HTML2FO。它可能会满足您的大部分需求。
You are on the right track. Yes, you will have to convert the HTML elements into XSL-FO elements. The XSL-FO engines read XSL-FO to know how to render it, so just copying HTML elements(bound to an HTML namespace or without a namespace) into an XSL-FO file will not work.
Take a look at HTML2FO. It might take care of the majority of your needs.