You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Lewis, Eric" <Er...@ipi.ch> on 2007/09/19 16:33:16 UTC

Page breaks and keeping blocks together

Hi

I'm having again a problem of page breaks and keeping things together (I
last wrote to this list in June 07).

I have a paragraph with a title and a body afterwards that must be kept
together if possible. As a fix to my last problem, I check whether the
title and body should be kept together always or whether I let FOP do
the page breaks.

This means I have something like
  <xsl:template match="histTxt">
    <fo:block>
      <xsl:choose>
        <xsl:when test="string-length(.) > $maximumLength">
          <xsl:attribute name="keep-together">auto</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="keep-together">always</xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates />
    </fo:block>
  </xsl:template>

In apply-templates, some escaped pseudo-HTML is converted into XSL-FO,
so at the end I have something like
<fo:block keep-together="always">
   <fo:inline font-weight="bold">my title</fo:inline>
   <fo:block/>my body bla bla bla bla bla<fo:block></fo:block>
</fo:block>

and for really long texts
<fo:block keep-together="auto">
   <fo:inline font-weight="bold">my other title</fo:inline>
   <fo:block/>Really, really long text, much longer than I care to type
here...<fo:block></fo:block>
</fo:block>

Most of the blocks are used for breaks, as you can see.

However, my problem is that at some point, the bold title is standing on
its own, and the body appears on the next page, like

my other title
--------------------------- page break
Really, really long text,
much longer than I care to
type here...

Not really nice! :-)
But hey, that's what orphans and widows are for, but after using them:

  <xsl:template match="histTxt">
    <fo:block>
      <xsl:choose>
        <xsl:when test="string-length(.) > $maximumLength">
          <xsl:attribute name="keep-together">auto</xsl:attribute>
          <xsl:attribute name="orphans">3</xsl:attribute>
          <xsl:attribute name="widows">3</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="keep-together">always</xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates />
    </fo:block>
  </xsl:template>

The result is much worse, the titles appear as orphans all over the
place. Besides, as I understand the default is 2, so this should never
happen (?)

I'm certainly doing something wrong, but what? I'd be glad for any hints
:-)

Best regards,
Eric

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org