Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL-FO

 
Jenny Zhang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jenny,
Thats XSLT & Xpath problem and not with XSL:FO,
i have changed the code for adding rows into the table,try this it will work(i tested in my machine).

Originally posted by Jenny Zhang:
XSL-FO file is very sensitive and if there is one single error in the file, the PDF will not be generated.

Try to code ur XSL to suits all needs,i mean try to use xsl:if or xsl:choose to suits all conditions.

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.

Try to use above code

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" />

U can supply variable from xsl to xsl:fo by using curly braces.
example
<xsl:variable name="colWidth1" select="'30mm'/>
<fo:table-column colum-widht="{$colWidth1}"/>
by this try u can try to code ur xsl to suits width according to ur XML file.Depending upon the xml file u can write a conditions on fixing number of columns.
Hope this helps.
Regards
Balaji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic