使用 <xsl:value-of> 在从 XSL FO 生成的 PDF 中插入换行符 [英] Inserting a line break in a PDF generated from XSL FO using <xsl:value-of>

查看:24
本文介绍了使用 <xsl:value-of> 在从 XSL FO 生成的 PDF 中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XSL FO 生成一个包含信息表格的 PDF 文件.这些列之一是描述"列.我用来填充这些描述字段之一的字符串示例如下:

I am using XSL FO to generate a PDF file containing a table with information. One of these columns is a "Description" column. An example of a string that I am populating one of these Description fields with is as follows:

This is an example Description.<br/>List item 1<br/>List item 2<br/>List item 3<br/>List item 4

在与此描述相对应的表格单元格内,我希望输出显示如下:

Inside the table cell that corresponds to this Description, I would like the output to display as such:

This is an example Description.
List item 1
List item 2
List item 3
List item 4

我从其他地方的搜索中了解到,您可以使用另一个 在 XSL FO 中进行换行:块> 元素.因此,甚至在我用 XSL 样式表解析 XML 之前,我将所有出现的 <br/> 替换为 <fo:block/>,以便字符串的字面值现在看起来像:

I've learned from searching elsewhere that you can make line breaks in XSL FO using an <fo:block></fo:block> within another <fo:block> element. Therefore, even before I parse the XML with my XSL stylesheet, I replace all occurrences of <br/> with <fo:block/>, so that the literal value of the string now looks like:

This is an example Description.<fo:block/>List item 1<fo:block/>List item 2<fo:block/>List item 3<fo:block/>List item 4

使用获取我使用的Description字符串时出现问题,示例如下:

The problem arises when the Description string I am using is obtained using <xsl:value-of>, example as follows:

<fo:block>
    <xsl:value-of select="descriptionStr"/>
</fo:block>

在这种情况下,输出到我的 PDF 文档的值是文字值,因此它看起来与前面的示例完全相同,其中包含所有 <fo:block/> 文字.我已经尝试手动硬编码 <fo:block/> 在另一个字符串的中间,它显示正确.例如.如果我写在我的样式表中:

In which case, the value that gets output to my PDF document is the literal value, so it looks exactly like the previous example with all the <fo:block/> literals. I've tried manually hard-coding the <fo:block/> in the middle of another string, and it displays correctly. E.g. if I write inside my stylesheet:

<fo:block>Te<fo:block/>st</fo:block>

它将正确显示为:

Te
st

但是当 位于 的值内时,这似乎不会发生. 语句.我试过在 SO 以及 Google 等上搜索这个,但无济于事.任何建议或帮助将不胜感激.谢谢!

But this does not seem to happen when the <fo:block/> is inside the value of an <xsl:value-of select=""/> statement. I've tried searching for this on SO as well as Google, etc. to no avail. Any advice or help will be greatly appreciated. Thank you!

推荐答案

你不应该使用 xsl:value-of 指令,而应该使用 xsl:apply-templates 指令:对于文本节点的内置规则将只输出它们的字符串值,对于空的 br 元素,你可以声明一个匹配 descriptionStr/brdescriptionStr//的规则br(取决于您的输入)以转换为空 fo:block.

You shouldn't use xsl:value-of instruction but xsl:apply-templates instead: for built-in rule for text node will just output their string value, and for empty br element you could declare a rule matching descriptionStr/br or descriptionStr//br (depending your input) in order to transform to empty fo:block.

这篇关于使用 &lt;xsl:value-of&gt; 在从 XSL FO 生成的 PDF 中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆