使用XSL-FO保留制表空间

时间:2015-06-23 07:52:34

标签: xslt whitespace xsl-fo preserve

我没有找到如下的明确问题:

我想在XSL-FO中将XML转换为PDF保留tabspace(ASCII 009)。 我的<fo:block />看起来像这样:

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

使用此配置,我可以保留换行符和普通空格,但不保留制表符空间。我在这篇文章中尝试了很多属性:https://github.com/xunit/xunit/issues/416 但它仍然无法奏效。如果我加入这个:

Forename:       John
Surname:        Smith

我明白了:

Forename: John
Surname: Smith

有关信息:

在我的XSL-FO中,我使用Layout-Master格式化页面。也许这可能是问题所在。 这是完整的XSL文件。

<?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 个答案:

答案 0 :(得分:0)

XSL-FO不处理除空格之外的选项卡。选项卡没有特定宽度,并且块中没有定义“制表位”。

XSL-FO中的定位是通过块和位置属性完成的。它看起来像你想要的,是使用一个额外的列并将值拆分为2:一个单元格中的第一部分,另一个单元格中的第二部分。