Search code examples
htmlxmlxsltxsl-fo

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>

Solution

  • 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>