cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Menke" <j...@eagleinfosystems.com>
Subject RE: tables in XSLT:FO
Date Mon, 05 Mar 2001 14:05:28 GMT
I have been using the following code to generate tables from XML files into
a PDF document.  I think you can probably alter it to work with your
document.  It will produce a table from XML formatted like below. Note that
you need to declare column widths for PDF documents.

<table numColumns="2" width="30mm">
				<tablesection name="Section 1 Name">
					<entry>Entry 1</entry>
					<entry>Entty 2</entry>
				</tablesection>
				<tablesection name="Section 2 Name">
					<entry>Entry 1</entry>
					<entry>Entry 2</entry>
				</tablesection>
</table>


<xsl:template name="columnFormatter">
	<xsl:param name="N" />
	<xsl:param name="MAX" />
	<xsl:param name="WIDTH" />
			<xsl:if test="$MAX>= $N">
					<fo:table-column column-width="{$WIDTH}"/>
					<xsl:call-template name="columnFormatter">
						<xsl:with-param name="N">
							<xsl:value-of select="$N + 1"/>
						</xsl:with-param>
						<xsl:with-param name="MAX">
							<xsl:value-of select="$MAX"/>
						</xsl:with-param>
						<xsl:with-param name="WIDTH">
							<xsl:value-of select="$WIDTH"/>
						</xsl:with-param>
					</xsl:call-template>
	         </xsl:if>
</xsl:template>

<xsl:template match="table">
  		<fo:table space-before="3mm" space-after="3mm">
				<xsl:call-template name="columnFormatter">
						<xsl:with-param name="N">
							1
						</xsl:with-param>
						<xsl:with-param name="MAX">
							<xsl:value-of select="@numColumns"/>
						</xsl:with-param>
						<xsl:with-param name="WIDTH">
							<xsl:value-of select="@width"/>
						</xsl:with-param>
				</xsl:call-template>
				<fo:table-body >

    						<fo:table-row  >
       								<xsl:apply-templates select="tablesection"/>
   						 </fo:table-row>


   						 <xsl:call-template name="rowCounter">
      					<xsl:with-param name="N" select="1"/>
  						 </xsl:call-template>
					</fo:table-body>
  		</fo:table>
</xsl:template>




<xsl:template name="rowCounter">
   <xsl:param name="N" />

   <xsl:if test="tablesection/entry[ $N ]">
     <fo:table-row>
      		<xsl:for-each select="tablesection">
        				<fo:table-cell border-width="0.5mm"  >
								<fo:block font-size="3mm" text-align="center" >
          									<xsl:apply-templates select="entry[ $N ]"/>
         			 							<xsl:text> </xsl:text>
								</fo:block>
        				</fo:table-cell>
     		 </xsl:for-each>
     </fo:table-row>

     <xsl:call-template name="rowCounter">
       		<xsl:with-param name="N" select="$N + 1"/>
     		</xsl:call-template>
   </xsl:if>
</xsl:template>

<xsl:template match="tablesection">
   		<fo:table-cell border-width="0.5mm" background-color="blue"  >
					<fo:block font-size="3mm"  font-weight="bold" color="white"
text-align="center">
					<xsl:value-of select="@name"/>
					</fo:block>
		</fo:table-cell>
</xsl:template>



> -----Original Message-----
> From: CM [mailto:mcai8cm2@ist4.co.umist.ac.uk]
> Sent: Monday, March 05, 2001 8:54 AM
> To: cocoon-users@xml.apache.org
> Subject: tables in XSLT:FO
>
>
> I have been doing some transformations from XML to PDF and my
> fo tables don't appear to be working
>
> I using the structure
>
> <fo:table>
>  <fo:table-body>
>   <fo:table-row>
>    <fo:table-cell>
>     <fo:block>
>     </fo:block>
>    </fo:table-cell>
>   </fo:table-row>
>  </fo:table-body>
> </fo:table>
>
> is this the correct struture??
>
> C
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail: <cocoon-users-help@xml.apache.org>
>
>


Mime
View raw message