我想要一个段落的第一行的首字母和所有其他段落的文本缩进。我正在使用以下代码:
<xsl:template match="paragraph">
<xsl:choose>
<!-- no text-indent, first letter bigger -->
<xsl:when test="fn:position() = 1">
<fo:block font-size="10pt" font-height="12pt">
<fo:inline font-size="18pt"><xsl:value-of
select="substring(.,1,1)"/></fo:inline>
<xsl:value-of select="substring(.,2)"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<!-- text-indent -->
<fo:block line-height="12pt"
text-indent="10pt">
<xsl:value-of select="."/></fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
这有效,但第一行的行高被放大,并且行之间有太多空间。
行高属性或
<fo:initial-property-set>
不工作。非常感谢。
编辑:我正在使用 fop
编辑:FOP 不支持
<fo:float>
或 <fo:initial-property-set>
.我使用 <fo:list>
尝试了另一个代码: <xsl:when test="fn:position() = 1">
<fo:block font-family="Times" font-size="10pt" line-height="12pt">
<fo:list-block>
<fo:list-item>
<fo:list-item-label>
<fo:block font-size="18pt"><xsl:value-of select="substring(.,1,1)"/></fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block><xsl:value-of select="substring(.,2)"/></fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</xsl:when>
结果如下所示:
所以我使用了图形空间
 
在 <fo:list-item-body>
的 value-of 选择模式中: <xsl:when test="fn:position() = 1">
<fo:block font-family="Times" font-size="10pt" line-height="12pt">
<fo:list-block>
<fo:list-item>
<fo:list-item-label>
<fo:block font-size="18pt"><xsl:value-of select="substring(.,1,1)"/></fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block><xsl:value-of select="(' ', ' ', substring(.,2))"/></fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block>
</xsl:when>
这不仅是陈词滥调,而且效果也不是很好:
有没有人有办法解决吗?
最佳答案
这个 xsl 片段,对问题中的第一个片段进行了最低限度的修改,使用 Apache FOP 产生了所需的结果:
<xsl:template match="paragraph">
<xsl:choose>
<!-- no text-indent, first letter bigger -->
<xsl:when test="not(preceding-sibling::paragraph)">
<fo:block line-height="12pt"
line-stacking-strategy="font-height">
<fo:inline font-size="18pt"><xsl:value-of
select="substring(.,1,1)"/></fo:inline>
<xsl:value-of select="substring(.,2)"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<!-- text-indent -->
<fo:block line-height="12pt"
text-indent="10pt">
<xsl:value-of select="."/></fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
要点:
关于xslt - 如何在不扩大行高的情况下在段落的第一行生成首字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21501333/