This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: xsl:fo table control question
- From: "Sami, Abdul (Netprosys)" <asami at spbank dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 5 Feb 2002 16:52:31 -0800
- Subject: RE: [xsl] xsl:fo table control question
- Reply-to: xsl-list at lists dot mulberrytech dot com
Apache FOP automatically start new page if it is required.
Below is the sample Xsl that i am using for generating pdf. It may help you.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
margin-right="1.5cm"
margin-left="1.5cm"
margin-bottom="2cm"
margin-top="1cm"
page-width="21.59cm"
page-height="27.94cm"
master-name="first">
<fo:region-before extent="6cm"/>
<fo:region-body margin-top="2.5cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-name="first">
<fo:static-content flow-name="xsl-region-before">
<xsl:apply-templates select="report/header" />
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block padding-left="5cm">
<fo:table space-after.optimum="1pt" width="15cm">
<fo:table-column column-width="12cm"/>
<fo:table-column column-width="3cm"/>
<fo:table-body>
<xsl:apply-templates
select="report/components" />
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="header">
<fo:table space-after.optimum="1pt">
<fo:table-column column-width="9cm"/>
<fo:table-column column-width="9cm"/>
<fo:table-body>
<xsl:apply-templates select="lines" />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="header/lines">
<xsl:for-each select="line">
<xsl:if test="position()=1">
<fo:table-row space-after.optimum="1pt">
<fo:table-cell number-columns-spanned="2">
<fo:block space-before.optimum="3pt"
space-after.optimum="5pt" line-height="12pt" font-size="10pt">
<xsl:value-of select="left"
/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
<xsl:if test="position()=2">
<fo:table-row line-height="14pt"
background-color="#EEEEEE">
<fo:table-cell>
<fo:block font-size="12pt"
font-weight="bold" space-before.optimum="3pt" margin-left="3pt">
<xsl:value-of select="left"
/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="end"
font-size="9pt" font-weight="bold">
<xsl:value-of select="right"
/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
<xsl:if test="position()=3">
<fo:table-row space-after.optimum="12pt"
background-color="#EEEEEE" line-height="12pt">
<fo:table-cell>
<fo:block font-size="9pt"
space-before.optimum="3pt" margin-left="3pt">
<xsl:call-template
name="space-4" />
<xsl:value-of select="left"
/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="end"
font-size="9pt" font-weight="bold">
<xsl:value-of select="right"
/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="components" >
<xsl:apply-templates select="component" />
</xsl:template>
<xsl:template match="component">
<xsl:apply-templates select="row | heading | summary" />
</xsl:template>
<xsl:template match="row">
<fo:table-row font-size="10pt" border-bottom-color="black"
border-bottom-width="1pt" border-bottom-style="solid"
space-before.optimum="2pt">
<xsl:for-each select="cell">
<fo:table-cell>
<xsl:if test="position()=1">
<xsl:call-template
name="left-data-block" />
</xsl:if>
<xsl:if test="position()=2">
<xsl:call-template
name="center-data-block" />
</xsl:if>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:template>
<xsl:template name="left-data-block">
<fo:block text-align="start">
<xsl:value-of select="content" />
</fo:block>
</xsl:template>
<xsl:template name="center-data-block">
<fo:block text-align="center">
<xsl:value-of select="content" />
</fo:block>
</xsl:template>
<xsl:template name="right-data-block">
<fo:block text-align="end">
<xsl:value-of select="content" />
</fo:block>
</xsl:template>
<xsl:template name="left-indented-data-block">
<fo:block text-align="start">
<xsl:call-template name="space-4" />
<xsl:value-of select="content" />
</fo:block>
</xsl:template>
<xsl:template name="space-1">
<fo:inline white-space-collapse="false"><fo:character character='
'/></fo:inline>
</xsl:template>
<xsl:template name="space-4">
<xsl:call-template name="space-1" />
<xsl:call-template name="space-1" />
<xsl:call-template name="space-1" />
<xsl:call-template name="space-1" />
</xsl:template>
<xsl:template match="heading">
<fo:table-row line-height="20pt" font-size="11pt"
background-color="#EEEEEE" space-after.optimum="8pt" font-weight="bold"
padding-left="3px" border-color="black" border-width="1pt"
border-style="solid">
<xsl:for-each select="cell">
<fo:table-cell>
<xsl:if test="position()=1">
<xsl:call-template
name="left-data-block" />
</xsl:if>
<xsl:if test="not(position()=1)">
<xsl:call-template
name="center-data-block" />
</xsl:if>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:template>
<xsl:template match="summary">
<fo:table-row line-height="20pt" font-size="11pt"
space-after.optimum="8pt" font-weight="bold" border-top-color="black"
border-top-width="1pt" border-top-style="solid">
<xsl:for-each select="cell">
<fo:table-cell>
<xsl:if test="position()=1">
<xsl:call-template
name="left-data-block" />
</xsl:if>
<xsl:if test="position()=2">
<xsl:call-template
name="center-data-block" />
</xsl:if>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: Khalid [mailto:k_ali@telusplanet.net]
Sent: Tuesday, February 05, 2002 12:35 PM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] xsl:fo table control question
Hello,I have just started experimenting xsl:fo,I was wondering if some one
could
guide me with problem.
the data I am working with,comes from the db in xml format.My question is I
guess how to manage the data in a way that should it span beyond the limits
of one page,it goes to the page 2,but if the data withing a certain table is
not that much to span on multiple pages,then only one <fo:table-row> must
appear
on a page and the next table-row section should go to the next page.
below is the code I have ,hopefully it will elaborate a little more about my
wuestion.
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name = "multi_table_test">
<fo:region-body region-name="body" margin-top="3pc"
margin-bottom="10pc"
margin-left="1pc" margin-right="1pc"/>
<fo:region-before region-name="header"
extent="2pc"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-name = "multi_table_test">
<fo:flow flow-name = "body">
<fo:table background-color="#FDFBD5"
padding-left="2px" padding-right="2px"
padding-bottom="2px" padding-top="0px" margin-left="0px" margin-right="0px"
margin-bottom="0px" margin-top="0px" border-color="#93BEE2"
border-style="solid"
border-left-width="1px" border-right-width="1px" border-bottom-width="1px"
border-top-width="1px"
width="565pt">
<fo:table-body>
<fo:table-row
font-weight="bold"><!-- This row is created once to create
the top headers -->
<fo:table-cell>
<fo:block>
Description
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
Code
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
Amount Owing
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row> <!-- this is created
dynamically depending upon the results
in the database -->
<fo:table-cell>
<fo:block>
Company 1
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
PL100A6T
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
124.35
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row> <!-- this is created
dynamically depending upon the results
in the database.this where I want to have a control of some sort.that will
determins
that if theere isn't more data in this segment then create next table-row in
the next page -->
<fo:table-cell>
<fo:block>
Company 2
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
PL101M6Z
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
9678.55
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
Thanks
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list