简体   繁体   English

如何避免XSL-FO中的块之前出现分页符?

[英]How to avoid page breaks before a block in XSL-FO?

I am converting HTML with paragraphs followed by blockquotes into FO using XSL. 我正在使用XSL将带段落的HTML转换为带有FOOT的段落引用。

How can I avoid page breaks between the paragraphs and the blockquote that follows? 如何避免在段落和后面的块引用之间出现分页符?

Page breaks following the blockquotes are fine. 块引用后的分页符很好。

Example: 例:

<p> Some paragraph..</p>
<blockquote>My reference</blockquote>
<p> Another paragraph..</p>
<blockquote>My reference</blockquote>

You need what is called a keep condition between the block generated by a normal p and the one generated by a blockquote . 您需要在正常p生成的块与blockquote生成的块之间的保持条件

In particular, as p is a general-purpose tag, I think the best option is to use the attribute keep-with-previous.within-page="always" in the fo:block generated for the blockquote HTML element. 特别地,由于p是通用标记,所以我认为最好的选择是在为blockquote HTML元素生成的fo:block使用属性keep-with-previous.within-page="always"

If you are using XSLT to create the XSL-FO output, you need something like this (you may need to adjust namespaces): 如果使用XSLT创建XSL-FO输出,则需要类似以下内容(可能需要调整名称空间):

<xsl:template match="blockquote">
    <fo:block keep-with-previous.within-page="always" ...other attributes...>
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

I think the most straightforward way would be to wrap the elements you want to keep together with a fo:block , and add a keep-with-next.within-page="always" attribute, as shown here : 我认为最简单的办法是包你想用共同保持的元素fo:block ,并添加keep-with-next.within-page="always"属性,如图所示在这里

<fo:block keep-with-next.within-page="always">
    ... content of p and blockquote elements
</fo:block>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM