xsl - Apache FOP - 是否可以允许列中断而不是分页符?

时间:2016-09-21 15:59:39

标签: xslt xsl-fo apache-fop

我有一个包含两列的项目。在顶部包含一些信息的块然后它包含一个相当小的表,但有时非常大(它是超级变量)。 当它变得太长时我需要在这个块中允许列分隔符,但是不需要分页符(除非表格太长以至于它不适合其他)。

我尝试过使用 keep-together.within-page ="总是" ,但这显然太严格了,而且表格已经过了我的边距,它仍然最终从第二列开始,让第一列相对空(我应该提到,第一列中的一些额外数据没有附加到块我想要保持在一起)。

我已经尝试过 keep-together.within-page =" 1" ,这至少使得超大型桌面在整个网页上正确破解,进入边缘,但他们仍然在第二列开始,第一列相对空。

我认为我会尝试明确添加 keep-together.within-column =" auto" ,但这没有任何作用。

我已经在网上搜索了好几天的答案,并且在这方面找不到多少。我已经查看了https://github.com/JuliaLang/ZMQ.jl/issues/69,但他们似乎并没有澄清这一点。 Apache FOP是否只将.within-page视为与.within-column相同?无论我是在页面内还是在列内使用,它似乎都会将其保留在列中;我认为这两者应具有非常独立的功能。

这是我fop -version

的输出
FOP Version SVN branches/fop-2_0    

示例XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                          xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="document">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
      <fo:simple-page-master 
    master-name="two_columns"
    page-height="8.5in"  page-width="11in" margin-top=".2in" 
    margin-bottom=".1in" margin-left=".2in" margin-right=".5in">          
    <fo:region-body margin-top=".95in" margin-bottom=".5in" column-count="2" />
    <fo:region-before extent=".95in"/>
    <fo:region-after extent=".6in"/>                  
      </fo:simple-page-master>
     </fo:layout-master-set>
     <fo:page-sequence master-reference="two_columns">
     <fo:static-content flow-name="xsl-region-before" font-family="Times Roman" text-transform="uppercase"
       font-size="8.6pt" >
       <fo:block>Document Title</fo:block>
     </fo:static-content>
     <fo:static-content flow-name="xsl-region-after" font-family="Times Roman" font-size="7.5pt">
        <fo:block>Document Footer</fo:block>
     </fo:static-content>
     <fo:flow flow-name="xsl-region-body" font-family="Times Roman" font-size="7.5pt">
       <fo:block>
       <fo:block>This is text that appears at the beginning of the document, and never again.</fo:block>
       <fo:block border-bottom="1px solid #000">It takes up space in the first column, and that's it.</fo:block>

        <xsl:for-each select="itemgroup">
        <fo:block keep-together.within-page="1"
            keep-together.within-column="auto">
            <fo:block keep-with-next="always">
                This text that should never be orphaned without the table
            </fo:block>
            <fo:table border="1px dashed #eee">
                <fo:table-header>
                 <fo:table-row>
                    <fo:table-cell><fo:block>Name</fo:block></fo:table-cell>
                    <fo:table-cell><fo:block>Date</fo:block></fo:table-cell>
                    <fo:table-cell><fo:block>Number</fo:block></fo:table-cell>
                 </fo:table-row>
                </fo:table-header>
                <fo:table-body>
                    <xsl:for-each select="item">
                        <fo:table-row>
                            <fo:table-cell>
                            <fo:block><xsl:value-of select="name"/></fo:block>
                            </fo:table-cell>
                            <fo:table-cell>
                            <fo:block><xsl:value-of select="date"/></fo:block>
                            </fo:table-cell>
                            <fo:table-cell>
                            <fo:block><xsl:value-of select="number"/></fo:block>
                            </fo:table-cell>
                        </fo:table-row>
                    </xsl:for-each>
                </fo:table-body>
            </fo:table>
        </fo:block>
        </xsl:for-each>
       </fo:block>
     </fo:flow> 
     </fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

您可以将上面的示例xsl与此xml一起使用(只需反复复制项目以使第一个表格更长 - 我不想浪费此页面上的空间):

<?xml version="1.0" encoding="UTF-8"?>
<document>
<itemgroup>
<item>
    <name>Test Person</name>
    <date>September 21, 2016</date>
    <number>42</number>
</item>
<item>
    <name>Test Person</name>
    <date>September 21, 2016</date>
    <number>42</number>
</item>
</itemgroup>
<itemgroup>
<item>
    <name>Test Person</name>
    <date>September 21, 2016</date>
    <number>42</number>
</item>
<item>
    <name>Test Person</name>
    <date>September 21, 2016</date>
    <number>42</number>
</item>
</itemgroup>
</document>

万一你不想再查一下(我知道我不知道),fop的语法是:

fop -xml sample.xml -xsl sample.xsl -pdf sample.pdf

0 个答案:

没有答案