|
next
|
Subject: Use XSL-FO to create tables from InfoPath XML Author: Marc Feickert Date: 08 Apr 2008 05:05 PM Originally Posted: 07 Apr 2008 06:12 PM
|
I am designing a method for capturing data, saving it as XML, and publishing it in a formatted PDF using xsl-fo.
My problem is with tables. With a standard table that I create myself, I get good results with some code I found while browsing the internet. When I apply my code the file AccessLevels.xml (see attached ZIP file), my tables come out fine. When I try to use it on Form1.xml (created from InfoPath), it chokes and gives me the error:
[WARNING] current implementation of tables requires a table-column for each column, indicating column-width
I am unsure how it clues in to the fact that InfoPath does tables differently, but it must be from the namespaces, because I stripped the <col> and <tbody> tags, and it made no difference.
I could use some help. Below is my XSLT for the creation of tables (full stylesheet is contained in the ZIP file).
<xsl:template match="xhtml:table|table">
<fo:table table-layout="fixed" space-before="5px" space-after="5px" border-before-style="solid" border-before-width="0.5px" border-before-color="999999" border-right-style="solid" border-right-width="0.5px" border-right-color="999999" border-left-style="solid" border-left-width="0.5px" border-left-color="999999">
<xsl:apply-templates select="//tr[position()=1]" mode="calculate_columns"/>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</xsl:template>
<!-- contentWidth is specified as xsl:param -->
<xsl:template match="xhtml:tr|tr" mode="calculate_columns">
<xsl:variable name="contentwidth" select="1"/>
<xsl:variable name="columns" select="count(th|td)"/>
<xsl:variable name="contentWidth"/>
<xsl:variable name="column-width">
<xsl:value-of select="concat($contentWidth div $columns,'cm')"/>
</xsl:variable>
<!--<xsl:variable name="column-width">
<xsl:value-of select="../../colgroup/col/@style"/>
</xsl:variable>-->
<xsl:for-each select="th|td">
<xsl:variable name="column-number">
<xsl:number level="multiple" count="th|td" format="1"/>
</xsl:variable>
<fo:table-column column-number="{$column-number}" column-width="{$column-width}"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="xhtml:tr|tr">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="xhtml:th|xhtml:td|td|th">
<fo:table-cell border-left-style="solid" border-left-width="0.5px" border-left-color="999999" border-after-style="solid" border-after-width="0.5px" border-after-color="999999" padding-after="3px" padding-before="3px" padding-left="3px" padding-right="3px">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>
files(2).zip zip file with two source files and style
|
|
|