2
votes

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.

2
You need to use the XSL-FO vocabulary for tables defined in its own specuser357812
It looks like an straightforward transformation table -> fo:table, tbody -> fo:table-body, tr -> fo:table-row and td -> fo:table-cell. What have you done so far?user357812
@Alejandro, well, I created an xslt code to convert html table tags to xsl-fo.code-gijoe
Why XSL-FO? Do you know "CSS+XHTML to PDF" technologies? See Why use XSL-FO instead of CSS2, for transform HTML into good PDF? question and answers.Peter Krauss

2 Answers

5
votes

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.

3
votes

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.