从 XSL-FO 生成的 PDF 中不需要的换行符?
Unwanted line breaks in PDF generated from XSL-FO?
我正在使用 XSLT 将一些 HTML 转换为 PDF。我遇到了一些不需要的换行符,我不确定为什么。
这里是 HTML 来源:
<li><strong>must</strong> only work in the occupation and for
the sponsor with the most recently approved nomination for
the holder <strong>unless</strong> the visa holder's
occupation is specified on a relevant instrument;
</li>
这是它在浏览器中的样子:
这是一些 XSLT:
<xsl:template match="condition/div">
<xsl:apply-templates select="div|p|ul|li|a|ol|strong"/>
</xsl:template>
<xsl:template match="li" mode="bullet">
<fo:list-item>
Unicode Bullet Character
<fo:list-item-label end-indent="label-end()">
<fo:block>
•
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-size="8pt" padding-bottom="2mm" padding-top="1mm">
<xsl:apply-templates />
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
<xsl:template match="strong">
<fo:block font-weight="bold">
<xsl:value-of select="." />
</fo:block>
</xsl:template>
...输出如下:
如您所见,<strong>
标记后出现不需要的换行符。有什么想法可以阻止这种情况发生吗?
你想要fo:inline
(like span
in HTML) here rather than fo:block
(比如HTML中的div
)。
改变
<xsl:template match="strong">
<fo:block font-weight="bold">
<xsl:value-of select="." />
</fo:block>
</xsl:template>
到
<xsl:template match="strong">
<fo:inline font-weight="bold">
<xsl:value-of select="." />
</fo:inline>
</xsl:template>
去掉strong
后的换行符。
我正在使用 XSLT 将一些 HTML 转换为 PDF。我遇到了一些不需要的换行符,我不确定为什么。
这里是 HTML 来源:
<li><strong>must</strong> only work in the occupation and for
the sponsor with the most recently approved nomination for
the holder <strong>unless</strong> the visa holder's
occupation is specified on a relevant instrument;
</li>
这是它在浏览器中的样子:
这是一些 XSLT:
<xsl:template match="condition/div">
<xsl:apply-templates select="div|p|ul|li|a|ol|strong"/>
</xsl:template>
<xsl:template match="li" mode="bullet">
<fo:list-item>
Unicode Bullet Character
<fo:list-item-label end-indent="label-end()">
<fo:block>
•
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-size="8pt" padding-bottom="2mm" padding-top="1mm">
<xsl:apply-templates />
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
<xsl:template match="strong">
<fo:block font-weight="bold">
<xsl:value-of select="." />
</fo:block>
</xsl:template>
...输出如下:
如您所见,<strong>
标记后出现不需要的换行符。有什么想法可以阻止这种情况发生吗?
你想要fo:inline
(like span
in HTML) here rather than fo:block
(比如HTML中的div
)。
改变
<xsl:template match="strong">
<fo:block font-weight="bold">
<xsl:value-of select="." />
</fo:block>
</xsl:template>
到
<xsl:template match="strong">
<fo:inline font-weight="bold">
<xsl:value-of select="." />
</fo:inline>
</xsl:template>
去掉strong
后的换行符。