从XSL-FO生成的PDF中不需要的换行符?

时间:2016-12-01 02:22:33

标签: html xml pdf xslt 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>

以下是浏览器中的内容:

enter image description here

以下是一些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>
                    &#x2022;
                </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>

...这是输出的样子:

enter image description here

如您所见,<strong>标记后会显示不需要的换行符。任何想法如何阻止这种情况发生?

1 个答案:

答案 0 :(得分:2)

您想要fo:inline(如HTML中的span)而非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之后的换行符。

相关问题