Preserving Tab-Space with XSL-FO

3.8k views Asked by At

I did not found an explicit question like the following:

I want to convert XML to PDF preserving tabspace (ASCII 009) in XSL-FO. My <fo:block /> looks like this:

<fo:block linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">
    <xsl:value-of select="orderText" />
</fo:block>

With this configuration I can preserve line breaks and normal spaces but no tab-space. I tried many attributes from this post: Preserving whitespace in PDF after XSL transform but it still doesn't work. If I put in this:

Forename:       John
Surname:        Smith

I get this:

Forename: John
Surname: Smith

For Information:

In my XSL-FO I use a Layout-Master for formatting the page. Maybe this could be the problem. This is the complete XSL-File.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ext="http://exslt.org/common" xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
  <xsl:preserve-space elements="orderText" />

  <!-- If we see an envelope, we create an FO document -->
  <xsl:template match="/tiff">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm"
          margin-top="1.5cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
          <fo:region-body margin-top="10mm" margin-bottom="5mm" />
          <fo:region-before region-name="header" />
          <fo:region-after region-name="footer" />
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:flow flow-name="xsl-region-body" text-align="justify" font-size="11pt">
          <!-- This will call generate stream headers (if applicable) -->
        <fo:block font-weight="bold" font-size="12pt" space-after="7mm">
            <xsl:text>Informationen zum Auftraggeber</xsl:text>    
        </fo:block>
        <fo:block space-after="7mm">
            <fo:table>
               <fo:table-body>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Auftragsnummer</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="orderId" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Erstellt von</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="creator" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Erstellt am</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="createDate" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Verwendete mTAN</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="mTAN" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
               </fo:table-body>
            </fo:table>         
        </fo:block>
        <fo:block font-weight="bold" font-size="12pt" space-after="7mm">
            <xsl:text>Informationen zum Kunden</xsl:text>    
        </fo:block>
        <fo:block space-after="7mm">
            <fo:table>
               <fo:table-body>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>ZAD-Kundennummer</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="customerId" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Name</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="surname" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Vorname</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="forename" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
               </fo:table-body>
            </fo:table>         
        </fo:block>
        <fo:block font-weight="bold" font-size="12pt" space-after="7mm">
            <xsl:text>Informationen zum Vertrag</xsl:text>    
        </fo:block>
        <fo:block space-after="7mm">
            <fo:table>
               <fo:table-body>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Versicherungsscheinnummer</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="vsnr" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Bestandsart</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="ba" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                     <fo:table-cell>
                        <fo:block>Konzerngesellschaft</fo:block>
                     </fo:table-cell>
                     <fo:table-cell>
                        <fo:block><xsl:value-of select="kg" /></fo:block>
                     </fo:table-cell>
                  </fo:table-row>
               </fo:table-body>
            </fo:table>         
        </fo:block>
        <fo:block font-weight="bold" font-size="12pt" space-after="7mm">
            <xsl:text>Auftragstext</xsl:text>

        </fo:block>
        <fo:block linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">
        <xsl:value-of select="orderText" />
        </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>
1

There are 1 answers

0
Florent Georges On BEST ANSWER

XSL-FO does not handle tabs other than being whitespaces. A tab does not have a specific width, and there are not "tab stops" defined in the blocks.

Positioning in XSL-FO is done through block, and position properties. It looks like what you want here, is to use an extra column and split the value in 2: the first part in one cell, the second part in the other.