Re: [xsl] xsl:fo - keeps and breaks problem..

Subject: Re: [xsl] xsl:fo - keeps and breaks problem..
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 12 Sep 2002 18:18:52 +0200
At 2002-09-12 09:08 +0100, Andy Joslin wrote:
some nodes have nested foo's inside them...

<foo type="a" name="Fooey">
      <foo type="x" name="FooChild"/>
      <foo type="y" name="FooChild2"/>

So far I've written a single template match for the foo element that
returns a fo:block (of full page width) for each match and calls itself
if it has any foo children, thereby producing nested fo:blocks where

The problem that I'm having is when trying to prevent any one foo result
from splitting over two pages. I'd like to keep all the contents of one
foo match together (ignore the nested ones for now); so either encourage
it to keep on one page or break and go to the next.

Have you tried putting in your one template rule the following test:

  <xsl:if test="not(parent::foo)">
    <xsl:attribute name="keep-together">always</xsl:attribute>

The above will only put the keep-together= on the "top level" foo elements, and will give an error if any one of them exceeds a page. Remember to not put this attribute on the literal result element within which you have the test, or if it is a child it will end up using that copy of the attribute node.

I wonder if you could probably get fancy and do the following:

  <xsl:attribute name="keep-together">
    <xsl:value-of select="count(ancestor-or-self::foo)"/>

This will make your top level foo's keep together with a strength of 1, then if one doesn't fit on a page it flows normally on the page but its children retain their strength of 2 and they, in turn, stay together on a page unless one of them should be too long and not be able to fit, after which their children will have a strength of 3 to keep together.

I hope this helps.

.................. Ken

-- Upcoming hands-on in-depth Europe: Sep 18-Sep 20,2002 XSLT/XPath and XSL-FO North America: Sep 30-Oct 4,2002

G. Ken Holman               mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next public training:           2002-09-13,18,19,30,10-03,12-08,
-                                                  2003-03-04,07

XSL-List info and archive:

Current Thread