如何在 Apache FOP 1.1 中真正将 fo:inline 个对象放在一起
How to really keep together fo:inline objects in Apache FOP 1.1
我有一个作者列表:
<titleStmt>
<author>GivenName1 Surname1</author>
<author>GivenName2 Surname2</author>
<author>GivenName3 Surname3</author>
<author>GivenName4 Surname4</author>
<author>GivenName5 Surname5</author>
<author>GivenName6 Surname6</author>
</titleStmt>
在初步转换为 XSL-FO 之后,我有:
<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
<fo:inline keep-together.within-line="always">GivenName1 Surname1</fo:inline>
<fo:inline keep-together.within-line="always">GivenName2 Surname2</fo:inline>
<fo:inline keep-together.within-line="always">GivenName3 Surname3</fo:inline>
<fo:inline keep-together.within-line="always">GivenName4 Surname4</fo:inline>
<fo:inline keep-together.within-line="always">GivenName5 Surname5</fo:inline>
<fo:inline keep-together.within-line="always">GivenName6 Surname6</fo:inline>
</fo:block>
我只需要在每条记录之间换行,而不是在记录内部换行(不想拆分 GivenName 和 Surname)。使用 keep-together.within-line
,我希望它应该可以工作,但没有。我得到的唯一结果是行溢出了页面边框,就像我将规则应用于整个块容器一样。我在这里遗漏了什么吗?
我用 FOP 1.1 测试了您的块,输出符合预期(多行,仅在姓氏后中断)。
我认为您可能在 fo:block
的祖先中有一个 keep-together.within-line="always"
或 keep-together="always"
(*),从而迫使整个块产生一行。
(*) XSL 1.1 Recommendation,第 5.11 Property Datatypes 节解释说:
keep-together="always"
is equivalent to a specification of keep-together.within-line="always"
keep-together.within-column="always"
keep-together.within-page="always"
这对我来说似乎有点令人讨厌,但添加不间断空格会按预期工作:
<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
<fo:inline keep-together.within-line="always">GivenName1 Surname1</fo:inline>
<fo:inline keep-together.within-line="always">GivenName2 Surname2</fo:inline>
<fo:inline keep-together.within-line="always">GivenName3 Surname3</fo:inline>
<fo:inline keep-together.within-line="always">GivenName4 Surname4</fo:inline>
<fo:inline keep-together.within-line="always">GivenName5 Surname5</fo:inline>
<fo:inline keep-together.within-line="always">GivenName6 Surname6</fo:inline>
</fo:block>
我使用 XSL 样式表生成它,所以:
<fo:inline>
<xsl:value-of select="replace(., '\s', ' ')"/>
</fo:inline>
我有一个作者列表:
<titleStmt>
<author>GivenName1 Surname1</author>
<author>GivenName2 Surname2</author>
<author>GivenName3 Surname3</author>
<author>GivenName4 Surname4</author>
<author>GivenName5 Surname5</author>
<author>GivenName6 Surname6</author>
</titleStmt>
在初步转换为 XSL-FO 之后,我有:
<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
<fo:inline keep-together.within-line="always">GivenName1 Surname1</fo:inline>
<fo:inline keep-together.within-line="always">GivenName2 Surname2</fo:inline>
<fo:inline keep-together.within-line="always">GivenName3 Surname3</fo:inline>
<fo:inline keep-together.within-line="always">GivenName4 Surname4</fo:inline>
<fo:inline keep-together.within-line="always">GivenName5 Surname5</fo:inline>
<fo:inline keep-together.within-line="always">GivenName6 Surname6</fo:inline>
</fo:block>
我只需要在每条记录之间换行,而不是在记录内部换行(不想拆分 GivenName 和 Surname)。使用 keep-together.within-line
,我希望它应该可以工作,但没有。我得到的唯一结果是行溢出了页面边框,就像我将规则应用于整个块容器一样。我在这里遗漏了什么吗?
我用 FOP 1.1 测试了您的块,输出符合预期(多行,仅在姓氏后中断)。
我认为您可能在 fo:block
的祖先中有一个 keep-together.within-line="always"
或 keep-together="always"
(*),从而迫使整个块产生一行。
(*) XSL 1.1 Recommendation,第 5.11 Property Datatypes 节解释说:
keep-together="always"
is equivalent to a specification ofkeep-together.within-line="always"
keep-together.within-column="always"
keep-together.within-page="always"
这对我来说似乎有点令人讨厌,但添加不间断空格会按预期工作:
<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
<fo:inline keep-together.within-line="always">GivenName1 Surname1</fo:inline>
<fo:inline keep-together.within-line="always">GivenName2 Surname2</fo:inline>
<fo:inline keep-together.within-line="always">GivenName3 Surname3</fo:inline>
<fo:inline keep-together.within-line="always">GivenName4 Surname4</fo:inline>
<fo:inline keep-together.within-line="always">GivenName5 Surname5</fo:inline>
<fo:inline keep-together.within-line="always">GivenName6 Surname6</fo:inline>
</fo:block>
我使用 XSL 样式表生成它,所以:
<fo:inline>
<xsl:value-of select="replace(., '\s', ' ')"/>
</fo:inline>