XSL-FO - Empty block elements

Jan picture Jan · Jul 4, 2009 · Viewed 18.3k times · Source

I have a quite simple template:

<xsl:template match="p">
    <fo:block>
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

How do I tell FO to keep empty lines even if the block is empty.

Answer

chiborg picture chiborg · Aug 7, 2009

Just add a <fo:leader/> element at the end of your <fo:block>. Like this:

<xsl:template match="p">
        <fo:block>
                <xsl:apply-templates/>
                <fo:leader />
        </fo:block>
</xsl:template>

The leader will do nothing for lines with content, and will create an empty line for lines without content.

Tested with Apache FOP and XEP.