You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Jen Liu <da...@yahoo.com> on 2002/07/13 20:00:13 UTC

XSL-FO TABLE

Hi,

We are on the project for letting the end user creating SQL and output into PDF format.  I are trying to do it by using FOP and convert  XML -> XSL -> PDF.  

We want to display the data on the PDF file like a resultset or a table kind of layout with the column header on top of the each page and the data underneath each column header. We are trying to use FO TABLE property to format it but I have the following questions:

1. Since the end user will create different SQL statements all the time, is it possible to create just one single XSL file which is dynamic enough to handle all different XML files containing the data info. The layout of all the XML files generated from the SQL execution will in the same layout. In XSL file, how can I define the columns dynamically? 

I here attached the XML & XSL files and the columns definition in XSL are hard-coded which just handles this specific XML file.  Would anybody tell me how to modify in XSL file (or maybe even my XML file) to make XSL dynamic for defining my columns?

2.  Is it possible to point FOP to two JSP pages containing the same info as my XML & XSL files and then read it info from JSP pages to generate PDF?

XML format:

<?xml version="1.0"?>
<RESULT>
	<COLUMN>
		<col name="APP_KEY"/>
		<col name="APP_NAME"/>
		<col name="APPTYPE_ID"/>
		<col name="APP_SEC"/>
		<col name="APP_NAV"/>
	</COLUMN>
	<ROW>

<DATA APP_KEY="1" APP_NAME="System-do not delete" APPTYPE_ID="0" APP_SEC="0" APP_NAV=" " />
		<DATA APP_KEY="2" APP_NAME="US1040 " APPTYPE_ID="0" APP_SEC="0" APP_NAV="pgHeaderReg.html" />

</ROW>
</RESULT>

XSL file (part of it):

<!-- The page content begins here. -->
<fo:table margin="1.5cm" border="1pt double green" >
        <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">
                    <fo:table-cell >
                           <fo:block text-align="center">APP_KEY</fo:block>
                    </fo:table-cell>
               <fo:table-cell >
				                           <fo:block text-align="center">APP_NAME</fo:block>
               </fo:table-cell>
               <fo:table-cell >
                           <fo:block text-align="center">APPTYPE_ID</fo:block>
               </fo:table-cell> 
				               <fo:table-cell >
                           <fo:block text-align="center">APP_SEC</fo:block>
               </fo:table-cell>        
               <fo:table-cell >
                           <fo:block text-align="center">APP_NAV</fo:block>
                </fo:table-cell>                                                            
           </fo:table-row>

           <!-- Use an XSLT <xsl:for-each> element to step through each row in the source file. -->
            <xsl:for-each select="/RESULT/ROW/DATA">
                 <fo:table-row>
                       <fo:table-cell font-size="10pt" border="1pt text-align="center">
                              <fo:block><xsl:value-of select="@APP_KEY"/></fo:block>
                       </fo:table-cell>
                       <fo:table-cell font-size="10pt" border="1pt text-align="center">
                              <fo:block><xsl:value-of select="@APP_NAME"/></fo:block>
                       </fo:table-cell>
                       <fo:table-cell font-size="10pt" border="1pt text-align="center">
                              <fo:block><xsl:value-of select="@APPTYPE_ID"/></fo:block>
                       </fo:table-cell> 
                       <fo:table-cell font-size="10pt" text-align="center">
                              <fo:block><xsl:value-of select="@APP_SEC"/></fo:block>
                       </fo:table-cell> 
                       <fo:table-cell font-size="10pt" text-align="center">
                              <fo:block><xsl:value-of select="@APP_NAV"/></fo:block>
                       </fo:table-cell> 
                 </fo:table-row>
            </xsl:for-each> 
  
        </fo:table-body>
    </fo:table> <!--The table containing the items ends here.-->   

Thanks in advance for the advice and the help!!!

Jen


            



---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

Re: XSL-FO TABLE

Posted by Antonio Fiol <fi...@w3ping.com>.
You may identify the string-length() of the data, but the actual length 
if you are not using a proportional font seems a bit difficult to determine.


Antonio Fiol

Jen Liu wrote:

> HI,
>
> One more Question:
>
> */Since the size of the columns are different and we have some columns 
> holding the descriptions and have very large size.  In code provided 
> by you, the length of all the columns are evenly divided by the number 
> of the columns.  Is there any way to identify the size of the data 
> held in the columns and define the width for each column in the table 
> in XSL file depending on the actual data size?/*
>
> Thanks again.
>
> Jen
>
>   */Jen Liu <da...@yahoo.com>/* wrote:
>
>      Hi, J.Pietschmann,
>
>     This is great!!!  I tried your code and it worked! 
>
>     I appreciate so much for the help and you solved my problem that I
>     had been struggling with in the past whole week.
>
>     Have a great weekend!!
>
>     Jen
>
>       */"J.Pietschmann" <j3...@yahoo.de>/* wrote:
>
>         Jen Liu wrote:
>         > 1. Since the end user will create different SQL statements
>         all the time,
>         > is it possible to create just one single XSL file which is
>         dynamic
>         > enough to handle all different XML files containing the data
>         info. The
>         > layout of all the XML files generated from the SQL execution
>         will in the
>         > same layout. In XSL file, how can I define the columns
>         dynamically?
>
>         Try
>
>
>         xmlns:fo="http://www.w3.org/1999/XSL/Format">
>
>
>
>
>         master-name="dibi-pdf"
>         page-width="29.1cm" page-height="21cm"
>         margin-top="0.5cm" margin-bottom="0.5cm"
>         margin-left="1cm" margin-right="1cm">
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>         > 2. Is it possible to point FOP to two JSP pages containing the
>         > same info as my XML & XSL files and then read it info from
>         JSP pages to
>         > generate PDF?
>
>         Yes, you can use URLs like "http://localhost/some/dir/dostuff.jsp@
>         Why do you think you need to? You can use a static XSLT, and
>         for DB
>         access you are better off firing SAX events from the row iterator.
>
>         J.Pietschmann
>
>
>     ------------------------------------------------------------------------
>     *Do You Yahoo!?*
>     Yahoo! Autos
>     <http://us.f205.mail.yahoo.com/ym/$rd_url/welcome/?http://autos.yahoo.com/>
>     - Get free new car price quotes
>
>
> ------------------------------------------------------------------------
> *Do You Yahoo!?*
> Yahoo! Autos <http://autos.yahoo.com/> - Get free new car price quotes 





Re: XSL-FO TABLE

Posted by Jen Liu <da...@yahoo.com>.
HI,
One more Question:
Since the size of the columns are different and we have some columns holding the descriptions and have very large size.  In code provided by you, the length of all the columns are evenly divided by the number of the columns.  Is there any way to identify the size of the data held in the columns and define the width for each column in the table in XSL file depending on the actual data size? 
Thanks again. 

Jen

  Jen Liu <da...@yahoo.com> wrote: 
 Hi, J.Pietschmann, 
This is great!!!  I tried your code and it worked!  
I appreciate so much for the help and you solved my problem that I had been struggling with in the past whole week. 
Have a great weekend!! 
Jen 
  "J.Pietschmann" <j3...@yahoo.de> wrote: Jen Liu wrote:
> 1. Since the end user will create different SQL statements all the time, 
> is it possible to create just one single XSL file which is dynamic 
> enough to handle all different XML files containing the data info. The 
> layout of all the XML files generated from the SQL execution will in the 
> same layout. In XSL file, how can I define the columns dynamically?

Try

xmlns:fo="http://www.w3.org/1999/XSL/Format">




master-name="dibi-pdf"
page-width="29.1cm" page-height="21cm"
margin-top="0.5cm" margin-bottom="0.5cm"
margin-left="1cm" margin-right="1cm">











































> 2. Is it possible to point FOP to two JSP pages containing the 
> same info as my XML & XSL files and then read it info from JSP pages to 
> generate PDF?

Yes, you can use URLs like "http://localhost/some/dir/dostuff.jsp@
Why do you think you need to? You can use a static XSLT, and for DB
access you are better off firing SAX events from the row iterator.

J.Pietschmann




---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes


---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

Re: XSL-FO TABLE

Posted by Jen Liu <da...@yahoo.com>.
 Hi, J.Pietschmann,
This is great!!!  I tried your code and it worked!  
I appreciate so much for the help and you solved my problem that I had been struggling with in the past whole week.
Have a great weekend!!
Jen
  "J.Pietschmann" <j3...@yahoo.de> wrote: Jen Liu wrote:
> 1. Since the end user will create different SQL statements all the time, 
> is it possible to create just one single XSL file which is dynamic 
> enough to handle all different XML files containing the data info. The 
> layout of all the XML files generated from the SQL execution will in the 
> same layout. In XSL file, how can I define the columns dynamically?

Try

xmlns:fo="http://www.w3.org/1999/XSL/Format">




master-name="dibi-pdf"
page-width="29.1cm" page-height="21cm"
margin-top="0.5cm" margin-bottom="0.5cm"
margin-left="1cm" margin-right="1cm">











































> 2. Is it possible to point FOP to two JSP pages containing the 
> same info as my XML & XSL files and then read it info from JSP pages to 
> generate PDF?

Yes, you can use URLs like "http://localhost/some/dir/dostuff.jsp@
Why do you think you need to? You can use a static XSLT, and for DB
access you are better off firing SAX events from the row iterator.

J.Pietschmann




---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

Re: XSL-FO TABLE

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Jen Liu wrote:
> 1. Since the end user will create different SQL statements all the time, 
> is it possible to create just one single XSL file which is dynamic 
> enough to handle all different XML files containing the data info. The 
> layout of all the XML files generated from the SQL execution will in the 
> same layout. In XSL file, how can I define the columns dynamically?

Try
  <?xml version="1.0"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:param name="tablewidth" select="24"/>
    <xsl:template match="RESULT">
      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
          <fo:simple-page-master
            master-name="dibi-pdf"
            page-width="29.1cm" page-height="21cm"
            margin-top="0.5cm" margin-bottom="0.5cm"
            margin-left="1cm" margin-right="1cm">
            <fo:region-body/>
          </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="dibi-pdf">
          <fo:flow flow-name="xsl-region-body">
            <fo:table margin="1.5cm" border="1pt double green" >
              <xsl:variable name="colwidth" select="$tablewidth div count(COLUMN/col)"/>
              <xsl:for-each select="COLUMN/col">
                <fo:table-column column-width="{$colwidth}cm" />
              </xsl:for-each>
              <fo:table-header>
                <fo:table-row>
                  <xsl:for-each select="COLUMN/col">
                    <fo:table-cell>
                      <fo:block font-size="12pt" font-weight="bold" text-align="center">
                        <xsl:value-of select="@name"/>
                      </fo:block>
                    </fo:table-cell>
                  </xsl:for-each>
                </fo:table-row>
              </fo:table-header>
              <fo:table-body>
                <xsl:variable name="coldesc" select="COLUMN/col"/>
                <xsl:for-each select="ROW/DATA">
                  <fo:table-row>
                    <xsl:variable name="data" select="."/>
                    <xsl:for-each select="$coldesc">
                      <xsl:variable name="colname" select="@name"/>
                      <fo:table-cell font-size="10pt" border="1pt solid green" text-align="center">
                        <fo:block><xsl:value-of select="$data/@*[name()=$colname]"/></fo:block>
                      </fo:table-cell>
                    </xsl:for-each>
                  </fo:table-row>
                </xsl:for-each>
              </fo:table-body>
            </fo:table>
          </fo:flow>
        </fo:page-sequence>
      </fo:root>
    </xsl:template>
  </xsl:stylesheet>


> 2.  Is it possible to point FOP to two JSP pages containing the 
> same info as my XML & XSL files and then read it info from JSP pages to 
> generate PDF?

Yes, you can use URLs like "http://localhost/some/dir/dostuff.jsp@
Why do you think you need to? You can use a static XSLT, and for DB
access you are better off firing SAX events from the row iterator.

J.Pietschmann