【问题标题】:fo:inline-elements create unwanted whitespacefo:inline-elements 创建不需要的空白
【发布时间】:2021-08-24 11:16:04
【问题描述】:

从一个 XML 文件(最初是一个 Word 文件),我用 XSLT 和 XSLFO 创建了一个 PDF。采用粗体字。这可行,但 PDF 在粗体字中包含不需要的空格(请参阅“不需要的结果”)。原因是fo:inlinefo:block 内创建了空格(Word 无法理解地将一些单词分成几个w:t 元素)。渲染器是 FOP。

我不知道如何将其关闭以生成空白。我已经尝试了一些空白设置,例如xsl:strip-space elementswhite-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>

【问题讨论】:

  • 也许你使用:。如果是这样,请将其更改为 如果您的源代码已经缩进,请使用:
  • 宾果游戏! output indent="no" 做到了。如此简单却又被忽视。谢谢!如果您将其发布为回复,我可以选择它。

标签: xml xslt whitespace xsl-fo


【解决方案1】:

也许你用过:&lt;xsl:output indent="yes" /&gt;

如果是这样,请将其更改为 &lt;xsl:output indent="no" /&gt;

如果您的源代码已经缩进,请使用:&lt;xsl:strip-space elements="w:r"/&gt;

【讨论】:

    猜你喜欢
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多