如何真正保持在一起:Apache FOP 1.1中的内联对象

时间:2016-03-01 13:59:12

标签: xsl-fo

我有一份作者名单:

<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,我希望它应该有效,但事实并非如此。我只有一个结果是溢出页面边框的行,就像我将规则应用于整个块容器一样。我在这里缺少什么吗?

2 个答案:

答案 0 :(得分:1)

我用FOP 1.1测试你的块,输出是预期的(几行,仅在姓氏后断开)。

我认为你可能在keep-together.within-line="always"的祖先中有一个keep-together="always"fo:block(*),从而迫使整个块产生一条线。

(*)XSL 1.1建议书第5.11 Property Datatypes节解释了:

  

keep-together="always"   等同于keep-together.within-line="always" keep-together.within-column="always" keep-together.within-page="always"

的规范

答案 1 :(得分:1)

对我来说这似乎有点讨厌,但添加不间断的空间按预期工作:

<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&#160;Surname1</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName2&#160;Surname2</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName3&#160;Surname3</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName4&#160;Surname4</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName5&#160;Surname5</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName6&#160;Surname6</fo:inline>
</fo:block>

我使用XSL样式表生成它,所以:

<fo:inline>
    <xsl:value-of select="replace(., '\s', '&#160;')"/>
</fo:inline>