Daniel Alexiuc Daniel Alexiuc - 5 days ago 6
HTML Question

Unwanted line breaks in PDF generated from XSL-FO?

I'm converting some HTML to a PDF using XSLT. I'm getting some unwanted line breaks, and I'm not sure why.

Here is the HTML source:

<li><strong>must</strong> only work in the occupation and for
the sponsor with the most recently approved nomination for
the holder <strong>unless</strong> the visa holder's
occupation is specified on a relevant instrument;
</li>


and here is what it looks like in a browser:

enter image description here

Here is some of the XSLT:

<xsl:template match="condition/div">
<xsl:apply-templates select="div|p|ul|li|a|ol|strong"/>
</xsl:template>

<xsl:template match="li" mode="bullet">
<fo:list-item>
Unicode Bullet Character
<fo:list-item-label end-indent="label-end()">
<fo:block>
&#x2022;
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-size="8pt" padding-bottom="2mm" padding-top="1mm">
<xsl:apply-templates />
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>

<xsl:template match="strong">
<fo:block font-weight="bold">
<xsl:value-of select="." />
</fo:block>
</xsl:template>


...and here is what the output looks like:

enter image description here

As you can see, unwanted line breaks appear after the
<strong>
tags. Any ideas how to stop this from happening?

Answer

You want fo:inline (like span in HTML) here rather than fo:block (like div in HTML).

Change

<xsl:template match="strong">
    <fo:block font-weight="bold">       
        <xsl:value-of select="." />    
    </fo:block>
</xsl:template>

to

<xsl:template match="strong">
    <fo:inline font-weight="bold">       
        <xsl:value-of select="." />    
    </fo:inline>
</xsl:template>

to eliminate the line breaks after strong.

Comments