How to insert a white space between two (inline) elements?
Solution 1
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>
Solution 2
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.
Adrian Maire
Enthusiast for most technological and scientific topics, specially computer science. I made a 300ECTS degree in computer science at UCLM (Spain) and I am currently working at Nexthink in Lausanne. I programmed my first ("finished") 2D video-game in VisualBasic-6 when I was 14, and since then, I spent most of my free time in personal projects: Real time graphics(opengl), AI neural networks, electronic, mechanical devices, house improvement...
Updated on June 07, 2022Comments
-
Adrian Maire almost 2 years
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?