我没有找到如下明确的问题:
我想在 XSL-FO 中将 XML 转换为 PDF 保留制表符(ASCII 009)。我的<fo:block />
样子是这样的:
<fo:block linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">
<xsl:value-of select="orderText" />
</fo:block>
使用此配置,我可以保留换行符和普通空格,但没有制表符空间。我从这篇文章中尝试了许多属性:Preserving whitespace in PDF after XSL transform 但它仍然不起作用。如果我输入这个:
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>