18

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.

Jan
  • 641
  • 1
  • 6
  • 22

3 Answers3

37

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.

chiborg
  • 26,978
  • 14
  • 97
  • 115
11

Or

<xsl:template match="p">
    <fo:block>
            <xsl:apply-templates/>
            &#x00A0;
    </fo:block>

&#x00A0; is the equivalent of &nbsp; in HTML (actually &nbsp; is a XML entity that is defined as A0 which is the Unicode character for Non Breaking Space).

XMLDUDE
  • 480
  • 4
  • 4
9

Alternatively,

<fo:block white-space-treatment="preserve"> </fo:block>
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84