Jakob Kofoed Janot
Jakob Kofoed Janot

Reputation: 23

How to avoid page breaks before a block in XSL-FO?

I am converting HTML with paragraphs followed by blockquotes into FO using XSL.

How can I avoid page breaks between the paragraphs and the blockquote that follows?

Page breaks following the blockquotes are fine.

Example:

<p> Some paragraph..</p>
<blockquote>My reference</blockquote>
<p> Another paragraph..</p>
<blockquote>My reference</blockquote>

Upvotes: 2

Views: 1621

Answers (2)

lfurini
lfurini

Reputation: 3788

You need what is called a keep condition between the block generated by a normal p and the one generated by a blockquote.

In particular, as p is a general-purpose tag, I think the best option is to use the attribute keep-with-previous.within-page="always" in the fo:block generated for the blockquote HTML element.

If you are using XSLT to create the XSL-FO output, you need something like this (you may need to adjust namespaces):

<xsl:template match="blockquote">
    <fo:block keep-with-previous.within-page="always" ...other attributes...>
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

Upvotes: 1

Parker
Parker

Reputation: 7519

I think the most straightforward way would be to wrap the elements you want to keep together with a fo:block, and add a keep-with-next.within-page="always" attribute, as shown here:

<fo:block keep-with-next.within-page="always">
    ... content of p and blockquote elements
</fo:block>

Upvotes: 0

Related Questions