我正在使用 XSL-FO 和 XML 生成 PDF。在文本框中,用户可以输入“1”等数据,然后按 ENTER,然后按“2”、ENTER、“3”等。但在 XML 和 PDF 中,输出是“1234567”。如何保留换行符?我已经尝试过了white-space-collapse
, linefeed-treatment
and white-space-treatment
但这没有帮助。
我的 XSL 看起来像:
<xsl:template match="AddCmt">
<fo:block keep-together="always"> Additional Comments
<fo:block-container border-style="solid" height="20mm" width="170mm" space-after="5mm">
<fo:block>
<xsl:attribute name="id">
<xsl:value-of select="../CMT_ID"/>
</xsl:attribute>
<xsl:value-of select="../ANS_CMT"/>
</fo:block>
</fo:block-container>
</fo:block>
</xsl:template>
当我输入以下内容时:
hello
medhavi
saraswat
这是我得到的 XML:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type='text/xsl' href='e:\tmm-09.3\src\pmod\WorkOrder.xsl'?>
<Root>
<WorkOrders>
<Detail>Id="ANS_436_FLD_1" Label="qq">qq</Detail>
<Ans Checked="0" Id="ANS_436_FLD_2" Label="ww">ww</Ans>
<ID>ANS_436_FLD</ID>
<ANS_FLD>0|0</ANS_FLD>
<CMT_ID>ANS_436_CMT</CMT_ID>
<ANS_CMT>hello medhavi saraswat</ANS_CMT>
<Warning>
<Line>warning 11</Line>
<Line>22</Line>
<Line>33</Line>
<Line>44</Line>
<Line></Line>
<Line>66</Line>
<Line>77</Line>
<Line></Line>
</Warning>
它应该与以下 xml 一起使用(您应该添加所有属性):
<xsl:template match="AddCmt">
<fo:block keep-together="always"> Additional Comments
<fo:block-container border-style="solid" height="20mm" width="170mm" space-after="5mm">
<fo:block wrap-option="wrap" linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve">
<xsl:attribute name="id">
<xsl:value-of select="../CMT_ID"/>
</xsl:attribute>
<xsl:value-of select="../ANS_CMT"/>
</fo:block>
</fo:block-container>
</fo:block>
</xsl:template>
但正如我在评论中提到的,如果您的 XML 已经没有换行符,那么您的 PDF 就不可能有换行符。您在问题中提到 XML 中没有换行符,因此 PDF 中没有换行符。
尝试检查一下为什么 XML 中没有换行符。如果您可以提供更多信息(您的 XML 片段、用于构建 XML 的代码……),请编辑您的答案并添加信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)