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

3

16

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?

Lusitania answered 17/8, 2014 at 9:7 Comment(0)
F
21

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>
Faradism answered 17/8, 2014 at 9:18 Comment(0)
V
4

The problem with

<fo:inline white-space="pre">  </fo:inline>

is that by default all whitespace-only text nodes within a stylesheet are stripped out, with the exception of those inside xsl:text elements. You can override this with xml:space="preserve"

<fo:inline xml:space="preserve" white-space="pre">  </fo:inline>

All whitespace text nodes that are descendants of an element with this attribute will be kept. Note that unlike normal namespaces you don't need to (and indeed are not allowed to) declare the xml: namespace prefix.

Varsity answered 17/8, 2014 at 9:53 Comment(0)
B
0

You can also use the following:

&amp;nbsp;
Browse answered 11/11, 2019 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.