I am on a web reporting tool project and the product will allow our end users to create their own SQL query and execute it against the database to get resultset. We want to output the resultset from XML file to PDF file.
We've got the
Java code to generate the XML containing the data retrieved from the database and the java code calls Apache's FOP open source to convert XML file to PDF format. Our Java code needs two input files: XML and XSL. The java code works fine and now we are struggling one creating the correct XML & XSL file. XSL-FO file is very sensitive and if there is one single error in the file, the PDF will not be generated.
We want to display the data on the PDF file like a resultset or a table layout with the column header on top of the each page and the data underneath each column header. I know I need to use FO table property to format it but I have the following problem:
1. From my XML & XSL files I created I was able to generate a PDF file but the data for all for all the columns are displayed in one column.
2. How to define the tabl-column dynmatically?
The following is the hard-coded column definition and I like to do in on the fly because each time the columns selected by the end user will be different.
<fo:table-column column-width="30mm" />
<fo:table-column column-width="30mm" />
If some one could take a look at the following XML & XSL files and see what is wrong, I would appreciate it so much.
XML file:
<?xml version="1.0"?>
<result>
<header>
<col name="APP_KEY"/>
<col name="APP_NAME"/>
<col name="APPTYPE_ID"/>
<col name="APP_SEC"/>
<col name="APP_NAV"/>
</header>
<row>
<field name="1"/>
<field name="US1040"/>
<field name="0"/>
<field name="0"/>
<field name=" "/>
</row>
<row>
<field name="2"/>
<field name="US1050"/>
<field name="0"/>
<field name="0"/>
<field name="5 "/>
</row>
</result>
XSL file:
<fo:flow flow-name="xsl-region-body">
<fo:table margin="1.5cm" border="1pt double green" >
<!--fo:table-column column-number="5" column-width="30mm" number-columns-repeated="5"/-->
<fo:table-column column-width="30mm" />
<fo:table-column column-width="30mm" />
<fo:table-column column-width="30mm" />
<fo:table-column column-width="30mm" />
<fo:table-column column-width="50mm" />
<fo:table-body>
<!--Create a header row for the column labels. -->
<fo:table-row font-size="12pt" font-weight="bold">
<xsl:for-each select="/result/header/col">
<fo:table-cell>
<fo:block>
<xsl:value-of select="@name"/>
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
<!-- Adding rows into the table-->
<xsl:for-each select="/result/row/field">
<fo:table-row>
<fo:table-cell font-size="10pt" border="1pt
double green" text-align="center">
<fo:block>
<xsl:value-of select="@name"/>
</fo:block>
</fo:table-cell> </fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>