This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Page break in table cell spanning across rows
- From: Jeff Beal <jeff dot beal at ansys dot com>
- To: "DocBook Mailing List (E-mail)" <docbook-apps at lists dot oasis-open dot org>
- Date: Thu, 06 Feb 2003 13:48:03 -0500
- Subject: DOCBOOK-APPS: Page break in table cell spanning across rows
A week or two ago (maybe three?) I posted about XEP causing page breaks in
table cells that span across multiple rows. The folks at XEP are working on
this, but they told me that I could put a keep-with-next.within column on
the table rows in question to prevent the problem. I made the following
stylesheet customizations to implement this with the DocBook 1.60.1
stylesheets.
I haven't tested it on every possible CALS table configuration, so there may
be some tables that will have spurious keep-with-next attributes on rows.
Jeff Beal
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:template match="row">
<xsl:param name="spans"/>
<fo:table-row>
<!-- Customization to add "keep-with-next.within-column" when the row
has a
cell spanning multiple rows. This fixes a problem where XEP will
break a page within a cell spanning multiple rows -->
<xsl:variable name="table-columns" select="ancestor::tgroup/@cols"/>
<xsl:variable name="columns-in-row">
<xsl:call-template name="count-row-columns">
<xsl:with-param name="row" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="*[@morerows]">
<!-- Found row with cell spanning down -->
<xsl:attribute name="keep-with-next.within-column">
<xsl:text>always</xsl:text>
</xsl:attribute>
</xsl:when>
<xsl:when test="$columns-in-row < $table-columns">
<!-- Found row with cell spanning through -->
<xsl:variable name="columns-in-next-row">
<xsl:call-template name="count-row-columns">
<xsl:with-param name="row" select="following-sibling::row[1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="following-sibling::row and
$columns-in-next-row < $table-columns">
<!-- Only add keep-with-next when the next row is also part of the
span -->
<xsl:attribute name="keep-with-next.within-column">
<xsl:text>always</xsl:text>
</xsl:attribute>
</xsl:if>
</xsl:when>
</xsl:choose>
<!-- End customization -->
<xsl:call-template name="anchor"/>
<xsl:apply-templates select="(entry|entrytbl)[1]">
<xsl:with-param name="spans" select="$spans"/>
</xsl:apply-templates>
</fo:table-row>
<xsl:if test="following-sibling::row">
<xsl:variable name="nextspans">
<xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
<xsl:with-param name="spans" select="$spans"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:apply-templates select="following-sibling::row[1]">
<xsl:with-param name="spans" select="$nextspans"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<!-- Template for counting the columns in a row, based on the number of
entrys
in the row and the number of entries with a span attribute. -->
<xsl:template name="count-row-columns">
<xsl:param name="row"/>
<xsl:choose>
<xsl:when test="not($row/*/@namest) and not($row/*/@spanname)">
<xsl:value-of select="count($row/*)"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="count-spanning-cells" select="$row/*[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="count-spanning-cells">
<xsl:variable name="entry" select="."/>
<xsl:variable name="spanned_columns">
<xsl:choose>
<xsl:when test="@spanname">
<xsl:variable name="spanspec" select="ancestor::*/spanspec[@spanname
= $entry/@spanname]"/>
<xsl:variable name="first_column"
select="$spanspec/ancestor::*/colspec[@colname=$spanspec/@namest]"/>
<xsl:variable name="end_column"
select="$spanspec/ancestor::*/colspec[@colname=$spanspec/@nameend]"/>
<xsl:value-of
select="count($first_column/following-sibling::colspec)
-
count($end_column/following-sibling::colspec)
+ 1"/>
</xsl:when>
<xsl:when test="@namest">
<xsl:variable name="first_column"
select="ancestor::*/colspec[@colname=$entry/@namest]"/>
<xsl:variable name="end_column"
select="ancestor::*/colspec[@colname=$entry/@nameend]"/>
<xsl:value-of
select="count($first_column/following-sibling::colspec)
-
count($end_column/following-sibling::colspec)
+ 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="following-sibling::*">
<xsl:variable name="columns_to_right">
<xsl:apply-templates select="following-sibling::*[1]"
mode="count-spanning-cells"/>
</xsl:variable>
<xsl:value-of select="$spanned_columns + $columns_to_right"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$spanned_columns"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>