How to insert a space between two (built-in) elements?

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

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

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

Of course, XML does not consider this empty space. I tried some solutions with inline elements, for example:

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

Also with field:

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

All these decisions ignore space, and the name looks like this: "1Introduction" instead of "1 introduction".

Any idea how to include a space between two (inline) elements?

+5
source share
2 answers

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> 
+11
source

A problem with

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

is that by default all text nodes for spaces only in the stylesheet are deleted, with the exception of elements inside xsl:text . You can override this with xml:space="preserve"

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

All white space text nodes that are descendants of an element with this attribute will be saved. Note: unlike regular namespaces, you do not need (and are not allowed) to declare an xml: space prefix.

+2
source

Source: https://habr.com/ru/post/1200520/


All Articles