Search code examples
xsltxsl-foapache-fop

How to insert a white space between two (inline) elements?


Context

I am creating an XSL-FO document to convert my XML text to PDF.

In the XSL-FO, I have two consecutive inline elements, I would like a white space between them:

<fo:block>
    <xsl:number/> <xsl:value-of select="@title"/>
</fo:block>

The expected result would be:

1 Introduction

Instead, I get

1Introduction

It seem XML do not consider this white space.

Attempts

I have tried several possible solutions, without success:

<fo:block>
    <xsl:number/><fo:inline white-space="pre">  </fo:inline><xsl:value-of select="@title"/>
</fo:block>

or

<fo:block>
    <xsl:number/><fo:inline margin-left="0.5cm"><xsl:value-of select="@title"/></fo:inline>
</fo:block>

None of those ideas produce an acceptable result.

The question:

How to include a white space between two (inline) elements?


Solution

  • Try:

    <fo:block>
        <xsl:number/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="@title"/>
    </fo:block>
    

    Or:

    <fo:block>
        <xsl:number/>
        <xsl:value-of select="concat(' ', @title)"/>
    </fo:block>