This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XSL-FO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL-FO" Watch "XSL-FO" New topic
Author

XSL-FO

Jenny Zhang
Greenhorn

Joined: Jul 12, 2002
Posts: 2
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>


Jenny
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
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


Spritle Software Blogs
 
 
subject: XSL-FO