开发者

Converting xml/html table to pdf via 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

开发者_Go百科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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜