Inserting a line break in a PDF generated from XSL FO using <xsl:value-of>

You could also replace <br/> with &#xA; and add a linefeed-treatment="preserve" attribute to your <fo:block>.

Something like:

<fo:block linefeed-treatment="preserve">This is an example Description.&#xA;List item 1&#xA;List item 2&#xA;List item 3&#xA;List item 4</fo:block>

Edit

Some users may need to use \n instead of &#xA; depending on how they are creating the XML. See Retain the &#xA; during xml marshalling for more details.


This helped me and should be simplest solution (working with Apache FOP 1.1):

Why not replace your <br/> with Unicode character called line separator.

   <xsl:template match="br">
      <xsl:value-of select="'&#x2028;'"/>
   </xsl:template>

See https://en.wikipedia.org/wiki/Newline#Unicode


The following code worked:

<fo:block white-space-collapse="false" 
    white-space-treatment="preserve" 
    font-size="0pt" line-height="15px">.</fo:block>

It makes the xsl processor thinks this block contains a line of text, which actually has a 0pt font size. You can customize line height by providing your own value.

Tags:

Xslt

Xsl Fo