Search code examples
xmlxsltwhitespacexsl-foapache-fop

Keep white spaces in the generated PDF with FOP


I'm implementing FOP using XSLT and XML files where I want to keep the white spaces between words.
This is how my XMLlooks like:

   <lines>
        <line1>       My Creation       </line1>
        <line2>                                 address one AAAAAAAAAAA</line2>
        <line3>            This is the              address of creation</line3>
   <lines>

What follows is The result in the form of PDF:

  My Creation
  address one AAAAAAAAAAA
  This is address of creation

But I need it to be like this:

                My Creation       
                                          address one AAAAAAAAAAA
                     This is the              address of creation

Hence preserving all spaces. I used the following line:

  <xsl:preserve-space elements="*"/>

But to no avail.
I googled for solutions but in vain.
Any help would be appreciated.


Solution

  • <fo:block font-family="monospace" white-space="pre" text-align="left">
        <xsl:value-of select="." />
    </fo:block>
    
    1. white-space="pre" will preserve the whitespaces
    2. font-family="monospace" will equalize the spaces' sizes with respect to that of the characters'