3

I've got a rather complicated table, which i think is the source of my problem. The table is filled based on data retrieved from an XML file from a client database. Here is an excerpt of the XSL code that I'm trying to apply to the XML:

<fo:table-row>
    <fo:table-cell number-columns-spanned="2">
        <fo:block/>
    </fo:table-cell>
    <fo:table-cell number-columns-spanned="2">
        <fo:block/>
    </fo:table-cell>
</fo:table-row>
<xsl:for-each select="xml/value">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@value"/>/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@othervalue"/>/>
            </fo:block>
        </fo:table-cell>
        </fo:table-row>
</xsl:for-each>

This is bundled together and treated like a single row, so if the page splits somewhere in this bigger row, it looks like the row is being split.

I've tried using keep-together.within-page="always", page-break-inside="avoid", keep-with-previous.within-page="always", and keep-with-next.within-page="always" on the table and on the iterated blocks in various combinations but nothing seems to stick. Can anyone spot a solution for this? Any help is appreciated, Thanks.

4

1 回答 1

1

我(不情愿地)使用的解决方法是嵌套表。使用此解决方案(如果它适合您),您最好table-layout="fixed"在表格上使用并明确指定列及其宽度,以确保列对齐。因此,我将引入一些进一步的模板来整理一下并提高可维护性:

<xsl:template match="Whatever">
    <fo:table table-layout="fixed">
        <xsl:call-template name="fourColumnTemplate"/>
        <fo:table-body>
            <!-- UNSEEN ROWS HERE -->
            <!-- UNSEEN ROWS HERE -->
            <!-- UNSEEN ROWS HERE -->
            <fo:table-row keep-together.within-page="always">
                <fo:table-cell number-columns-spanned="4">
                    <fo:block>
                        <xsl:call-template name="outputXmlValueTable">
                            <xsl:with-param name="xmlNodes" select="xml/value"/>
                        </xsl:call-template>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template name="fourColumnTemplate">
    <!-- note that these values should only be specified in one place for maintenance reasons -->
    <fo:table-column column-width="proportional-column-width(2)"/>
    <fo:table-column column-width="proportional-column-width(3)"/>
    <fo:table-column column-width="proportional-column-width(2)"/>
    <fo:table-column column-width="proportional-column-width(3)"/>
</xsl:template>

<xsl:template name="outputXmlValueTable">
    <xsl:param name="xmlNodes"/>
    <fo:table table-layout="fixed">
        <xsl:call-template name="fourColumnTemplate"/>
        <fo:table-header>
            <fo:table-row>
                <fo:table-cell number-columns-spanned="2">
                    <fo:block>Title1</fo:block>
                </table-cell>
                <fo:table-cell number-columns-spanned="2">
                    <fo:block>Title2</fo:block>
                </table-cell>
            </fo:table-row>
        </fo:table-header>
        <fo:table-body>
            <xsl:apply-templates select="$xmlNodes" mode="outputXmlValueRow"/>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="*" mode="outputXmlValueRow">
    <fo:table-row>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@value"/>/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell number-columns-spanned="2">
            <fo:block>
                <xsl:value-of select="@othervalue"/>/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>
于 2013-07-01T16:46:58.823 回答