有条件的页面 - 在fo:table中断

时间:2015-01-26 15:15:55

标签: xsl-fo page-break

我尝试在我的fo:table中插入一个条件分页符 - 没有成功!

这是我的XSL:FO模板的一部分:

<xsl:template match="Lignes">
        <fo:block-container width="100%" top="11cm"
            position="absolute">
            <fo:block color="black" font-family="Tahoma" font-size="12px"
                font-weight="normal">
                my title
            </fo:block>

            <fo:block white-space-collapse="false"
                white-space-treatment="preserve" font-size="0pt" line-height="10px">.
            </fo:block>

            <fo:block color="black" font-family="Tahoma" font-size="10px"
                font-weight="normal">
                <fo:table table-layout="fixed" border-spacing="3px 3px">
                    <fo:table-column column-width="20%" />
                    <fo:table-column column-width="30%" />
                    <fo:table-column column-width="8%" />
                    <fo:table-column column-width="15%" />
                    <fo:table-column column-width="12%" />
                    <fo:table-column column-width="15%" />

                    <fo:table-header background-color="#EFEFEF"
                        border-width="1px" border-style="solid">
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="center">Column 1
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="center">Column 2
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="center">Column 3
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="right">Column 4
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="right">Column 5
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="3px">
                            <fo:block text-align-last="right">Column 6
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-header>

                    <fo:table-footer>
                        <fo:table-row space-before.optimum="0pt">
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center" padding="5px"
                                    font-size="10px" font-weight="normal">
                                    Total H.T
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="right" background-color="white"
                                    border-color="black" border-width="1px" border-style="solid"
                                    font-weight="bold" padding="3px">
                                    <xsl:value-of
                                        select="format-number(/Devis/Corps/Footer/mt_ht, '### ###.00')" />
                                </fo:block>
                            </fo:table-cell>
                        </fo:table-row>

                        <xsl:for-each select="/Devis/Corps/Footer/TVA/Ligne_TVA">
                            <fo:table-row space-before.optimum="0pt">
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center" padding="5px"
                                        font-size="10px" font-weight="normal">
                                        <xsl:text>TVA (</xsl:text>
                                        <xsl:value-of select="taux" />
                                        <xsl:text> %)</xsl:text>
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="right" background-color="white"
                                        border-color="black" border-width="1px" border-style="solid"
                                        font-weight="bold" padding="3px">
                                        <xsl:value-of select="format-number(mt_tva, '### ###.00')" />
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </xsl:for-each>

                        <fo:table-row space-before.optimum="0pt">
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center">
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="center" padding="5px"
                                    font-size="10px" font-weight="normal">
                                    Total T.T.C
                                </fo:block>
                            </fo:table-cell>
                            <fo:table-cell padding="3px">
                                <fo:block text-align-last="right" background-color="white"
                                    border-color="black" border-width="1px" border-style="solid"
                                    font-weight="bold" padding="3px">
                                    <xsl:value-of
                                        select="format-number(/Devis/Corps/Footer/mt_ttc, '### ###.00')" />
                                </fo:block>
                            </fo:table-cell>
                        </fo:table-row>
                    </fo:table-footer>

                    <fo:table-body background-color="white" border-color="black"
                        border-width="1px" border-style="solid">
                        <xsl:for-each select="Ligne">

                            <!-- page break -->
                            <xsl:if test="position() mod 3 = 0">
                                <fo:table-row break-before="page">
                                    <fo:table-cell padding="3px">
                                        <fo:block text-align-last="center">

                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </xsl:if>

                            <fo:table-row space-before.optimum="0pt">
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                        <xsl:value-of select="ref" />
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                        <xsl:value-of select="designation" />
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="center">
                                        <xsl:value-of select="qte" />
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="right">
                                        <xsl:value-of select="format-number(pu_ht, '### ###.00')" />
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="right">
                                        <xsl:if test="remise > 0">
                                            <xsl:value-of select="format-number(remise, '### ###.00')" />
                                        </xsl:if>
                                        <xsl:if test="contains(remise, '%')">
                                            <xsl:value-of select="remise" />
                                        </xsl:if>
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding="3px">
                                    <fo:block text-align-last="right">
                                        <xsl:value-of select="format-number(total_ht, '### ###.00')" />
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </xsl:for-each>
                    </fo:table-body>
                </fo:table>
            </fo:block>
        </fo:block-container>
    </xsl:template>

这是我的XML文件的一部分:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Devis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="_dt.xsd">
    <Corps>
        <Lignes>
            <Ligne>
                <ref>ASUS97_105</ref>
                <designation>produit 1</designation>
                <qte>1</qte>
                <pu_ht>160</pu_ht>
                <remise>34.55</remise>
                <total_ht>125.45</total_ht>
            </Ligne>
            <Ligne>
                <ref>FORT1</ref>
                <designation>produit 2</designation>
                <qte>1</qte>
                <pu_ht>60</pu_ht>
                <remise>15%</remise>
                <total_ht>51</total_ht>
            </Ligne>
            <Ligne>
                <ref>FORT2</ref>
                <designation>produit 3</designation>
                <qte>1</qte>
                <pu_ht>70</pu_ht>
                <remise></remise>
                <total_ht>60</total_ht>
            </Ligne>
            <Ligne>
                <ref>FORT3</ref>
                <designation>produit 4</designation>
                <qte>1</qte>
                <pu_ht>80</pu_ht>
                <remise></remise>
                <total_ht>60</total_ht>
            </Ligne>
            <Ligne>
                <ref>FORT4</ref>
                <designation>produit 5</designation>
                <qte>1</qte>
                <pu_ht>70</pu_ht>
                <remise></remise>
                <total_ht>60</total_ht>
            </Ligne>
            <Ligne>
                <ref>FORT5</ref>
                <designation>produit 6</designation>
                <qte>1</qte>
                <pu_ht>80</pu_ht>
                <remise></remise>
                <total_ht>60</total_ht>
            </Ligne>
        </Lignes>
        <Footer>
            <mt_ht>185.45</mt_ht>
            <TVA>
                <Ligne_TVA>
                    <mt_tva>37.09</mt_tva>
                    <taux>20</taux>
                </Ligne_TVA>
            </TVA>
            <mt_ttc>222.54</mt_ttc>
            <duree>60</duree>
            <Check>
                <path>checkbox.png</path>
                <path_pdf>file:/D:/checkbox.png</path_pdf>
            </Check>
            <Commentaire_refus_devis>
                <Ligne_commentaire>
                    <commentaire>commentaire 1
                    </commentaire>
                </Ligne_commentaire>
                <Ligne_commentaire>
                    <commentaire>commentaire 2
                    </commentaire>
                </Ligne_commentaire>
                <Ligne_commentaire>
                    <commentaire>commentaire 3
                    </commentaire>
                </Ligne_commentaire>
            </Commentaire_refus_devis>
        </Footer>
    </Corps>
</Devis>

这不是我的PDF文件中的分页!

有什么想法吗?

提前感谢你

FM

1 个答案:

答案 0 :(得分:0)

您的fo:table位于绝对定位的fo:block-container内。

根据XSL Specifications

  

只有绝对位置=&#34; auto&#34;可能有页面/列   符。

     

对于其他值,将忽略任何keep和break属性

因此,您的分页符被正确忽略。

建议的更改:

  • 删除fo:block-container
  • 代替top="11cm"上的fo:block-container,您可以在margin-top="11cm"上使用fo:region-body(或者将当前值加上11厘米)