2

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.

code-gijoe
  • 6,949
  • 14
  • 67
  • 103
  • You need to use the XSL-FO vocabulary for tables defined in its own [spec](http://www.w3.org/TR/xsl/#d0e11404) –  Feb 19 '11 at 16:09
  • 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? –  Feb 19 '11 at 23:14
  • @Alejandro, well, I created an xslt code to convert html table tags to xsl-fo. – code-gijoe Feb 20 '11 at 22:09
  • 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?](http://stackoverflow.com/q/10641667/287948) question and answers. – Peter Krauss Jul 26 '12 at 18:22

2 Answers2

5

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.

code-gijoe
  • 6,949
  • 14
  • 67
  • 103
3

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.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147