我从一个 XML 文件(最初是一个 Word 文件)创建了一个带有 XSLT 和 XSLFO 的 PDF。应采用粗体。这有效,但 PDF 中的粗体字包含不需要的空格(请参阅“不需要的结果”)。原因是在其中fo:inline
创建了空格fo:block
(Word 无法理解地将一些单词拆分为多个w:t
元素)。渲染器是 FOP。
我不知道如何关闭生成空白区域。我已经尝试了一些空白设置,比如xsl:strip-space elements
and white-space-collapse
,但没有成功。
为什么样式表会在它们之间创建空白fo:inline
,我该如何解决这个问题?
不想要的结果
来自 PDF:“ ... weil Fi l mmaterial in der ... ”
想要的结果
应该是:“ ... weil Filmmaterial in der ... ”
SOURCE,为了清楚起见,由一些元素(不是关键的)缩短
<div class="listlevel-1">
<w:p>
<w:r>
<w:t>... weil </w:t>
</w:r>
<w:r>
<w:t>Fi</w:t>
</w:r>
<w:r>
<w:t>l</w:t>
</w:r>
<w:r>
<w:t>mmaterial</w:t>
</w:r>
<w:r>
<w:t> in der digitalen ...</w:t>
</w:r>
</w:p>
</div>
XSLT-Stylesheet,为了清楚起见,通过一些元素(不是关键的)缩短
2 个 XSLT 样式表在转换过程中交织在一起。问题发生在列表中。一个样式表转换列表 (1),第二个样式表转换所有粗体、斜体或下划线的文本元素(w:t 元素)。
1)
<xsl:template match="//div[@class = 'listlevel-1']/w:p">
<fo:list-item xsl:use-attribute-sets="listitem">
<fo:list-item-label xsl:use-attribute-sets="itemlabel">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body xsl:use-attribute-sets="itembody">
<fo:block>
<xsl:apply-templates select="w:r/w:t"/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
几个xsl:choose
分支用来查询几个条件;条件 2 和 3 由于长度原因未在此处列出,但它们的结构与条件 1 完全相同。
<xsl:template match="//w:t">
<xsl:choose>
<xsl:when test="../w:rPr/w:b">
<xsl:choose>
<xsl:when test="../w:rPr/w:u">
<xsl:choose>
<xsl:when test="../w:rPr/w:i">
<fo:inline>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="text-decoration">underline</xsl:attribute>
<xsl:attribute name="font-style">italic</xsl:attribute>
<xsl:apply-templates/>
</fo:inline>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="text-decoration">underline</xsl:attribute>
<xsl:apply-templates/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:when>
...
</xsl:choose>
</xsl:template>
FO-File,代码在 FO 文件中的样子:
<fo:block>... weil
<fo:inline font-weight="bold">Fi</fo:inline>
<fo:inline font-weight="bold">l</fo:inline>
<fo:inline font-weight="bold">mmaterial</fo:inline> in ...
</fo:block>
也许你用过:<xsl:output indent="yes" />
。
如果是这样,请将其更改为 <xsl:output indent="no" />
如果您的源代码已经缩进,请使用: <xsl:strip-space elements="w:r"/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句