在使用单元格中包含大量文本的表格时,我遇到了样式问题。不幸的是,有时文本被分页符分隔。正如您在下图中看到的,第 3 行中的第1段除以分页符。
我们需要的是第3 行第 1 行第 1 行与段落的其余部分一起放到下一页。
我们尝试使用诸如“孤儿”和“寡妇”之类的属性,但这些属性在表格单元格中似乎没有任何影响。我们还尝试使用带有keep-together属性的块,但段落可能会大于一页,因此内容会被截断。我们唯一能想到的另一件事是使用keep-with-next和 fo:blocks,我们在一行的前几段中使用它。但这看起来草率、复杂,更像是一个经验法则估计。
我整理了一个可以使用http://www.utilities-online.info/foprender/进行测试的“最小”示例。我希望你能帮助我解决问题。也许你也可以告诉我为什么“孤儿”和“寡妇”在这里似乎不起作用。
先感谢您!
XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<heading>head1</heading>
<description>
<p>row1 paragraph1 line1
row1 paragraph1 line2
row1 paragraph1 line3
row1 paragraph1 line4
row1 paragraph1 line5</p>
<p>row1 paragraph2 line1
row1 paragraph2 line2
row1 paragraph2 line3
row1 paragraph2 line4</p>
</description>
</item>
<item>
<heading>head1</heading>
<description>
<p>row2 paragraph1 line1
row2 paragraph1 line2
row2 paragraph1 line3
row2 paragraph1 line4
row2 paragraph1 line5</p>
<p>row2 paragraph2 line1
row2 paragraph2 line2
row2 paragraph2 line3
row2 paragraph2 line4
row2 paragraph2 line5
row2 paragraph2 line6
row2 paragraph2 line7</p>
</description>
</item>
<item>
<heading>head1</heading>
<description>
<p>row3 paragraph1 line1
row3 paragraph1 line2
row3 paragraph1 line3
row3 paragraph1 line4
row3 paragraph1 line5</p>
<p>row3 paragraph2 line1
row3 paragraph2 line2
row3 paragraph2 line3
row3 paragraph2 line4</p>
</description>
</item>
</root>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml" standalone="no" omit-xml-declaration="no"/>
<xsl:template match="//root">
<fo:root language="DE">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-landscape" page-height="21cm" page-width="29.7cm" margin-top="5mm" margin-bottom="5mm" margin-left="5mm" margin-right="5mm">
<fo:region-body margin-top="25mm" margin-bottom="20mm"/>
<fo:region-before region-name="xsl-region-before" extent="25mm" display-align="before" precedence="true"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-landscape">
<fo:flow reference-orientation="0" border-collapse="collapse" flow-name="xsl-region-body">
<fo:table>
<fo:table-column column-width="80%"/>
<fo:table-body>
<xsl:apply-templates select="item"/>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="item">
<fo:table-row>
<fo:table-cell border="solid">
<fo:block>
<xsl:value-of select="heading"/>
</fo:block>
<fo:block linefeed-treatment="preserve" orphans="4" widows="4">
<xsl:apply-templates select="description"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="//description/p">
<fo:inline><xsl:value-of select="text()"/></fo:inline>
</xsl:template>
</xsl:stylesheet>
编辑将 p-tag 添加到 xml 输入。我发布了错误版本的xml。