Fop 0.20.5为什么这不起作用?

时间:2014-12-01 09:39:19

标签: xml pdf xslt margin apache-fop

我遇到了以下问题并且一直试图找到解决方案,但到目前为止我没有运气...我正在尝试从xml生成pdf ...在我的xsl文件中我有一些嵌入式xml用作我应用各种模板的静态内容。虽然这一切都完全适用于fop 1.1,但同样不适用于fop 0.20.5,我需要找到一种解决方法或某种解决方案....以下代码片段在fop 1.1上工作正常并生成相应的部分完全符合pdf:

<xsl:apply-templates select="document('')/xsl:stylesheet/data:data/DOCUMENT"/>
    <xsl:template match="DOCUMENT">

 <xsl:param name="filename" select="document('')/xsl:stylesheet/data:data/DOCUMENT/SECTIONS/SECTION/PARAGRAPHS/FILE"></xsl:param>
    <!-- new doc, new page break-->
    <fo:table table-layout="fixed" width="100%" space-before="5pt">
        <fo:table-column column-width="30mm"/>
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell border-collapse="collapse">
                    <fo:block break-before="page"></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>

    <fo:block>
        <fo:marker marker-class-name="title">
            <xsl:value-of select="PRODUCT_CATEGORY"/>
        </fo:marker>
    </fo:block>

    <!-- Addition for the title of the product before the termDOC -->
    <fo:table table-layout="fixed" width="100%" border="none" border-collapse="collapse">
        <fo:table-column column-width="proportional-column-width(1)"/>
        <fo:table-body>
            <fo:table-row display-align="before">
                <fo:table-cell font-size="12pt" text-align="left" font-family="arial">
                    <fo:block space-before="5pt" font-family="arialbd" font-size="12pt" padding-left="2mm" padding-top="1mm" padding-bottom="1mm">
                        <xsl:value-of select="$titlos"/>        
                    </fo:block>
                    <fo:block space-before="5pt" font-family="arialbd" font-size="12pt" padding-left="2mm" padding-top="1mm" padding-bottom="1mm">                          
                        <xsl:if test="CODE='31103'">
                            some text 
                        </xsl:if>                           
                    </fo:block>                     
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
    <!-- end of title -->

    <xsl:for-each select="document('')/xsl:stylesheet/data:data/DOCUMENT/SECTIONS/SECTION">
        <fo:table table-layout="fixed" width="100%" border-collapse="collapse" space-before="4pt">
            <fo:table-column column-width="5mm"/>
            <fo:table-column column-width="170mm"/>
            <fo:table-column column-width="5mm"/>
            <fo:table-body>

                <xsl:if test="./HEDER">
                    <fo:table-row>
                        <fo:table-cell padding-before="3pt" border-collapse="collapse">
                            <fo:block/>
                        </fo:table-cell>
                        <fo:table-cell padding-before="3pt" border-collapse="collapse">
                            <fo:block font-size="11pt" text-align="left" font-family="arial" color="darkblue">
                                <xsl:value-of select="HEDER"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding-before="3pt">
                            <fo:block/>
                        </fo:table-cell>
                    </fo:table-row>
                </xsl:if>
                <xsl:if test="HEADER">
                    <fo:table-row>
                        <fo:table-cell padding-before="8pt" padding-after="9pt" border-collapse="collapse">
                            <fo:block/>
                        </fo:table-cell>
                        <fo:table-cell padding-before="9pt" padding-after="9pt" border-collapse="collapse">
                            <fo:block font-size="9pt" text-align="left" font-family="arial" color="darkblue">
                                <xsl:value-of select="HEADER"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding-before="8pt" padding-after="8pt">
                            <fo:block/>
                        </fo:table-cell>
                    </fo:table-row>
                </xsl:if>
                <fo:table-row>
                    <fo:table-cell border-collapse="collapse">
                        <fo:block/>
                    </fo:table-cell>
                    <fo:table-cell border-collapse="collapse">
                        <xsl:for-each select="PARAGRAPHS">
                            <xsl:for-each select="DATA">
                                <xsl:if test="@type='normal' and ./INFO">
                                    <fo:block space-before="10pt" space-after="10pt" font-size="9pt" text-align="left" font-family="arial">
                                        <xsl:value-of select="INFO"/>
                                    </fo:block>
                                </xsl:if>
                                <xsl:if test="@type='list' and ./INFO">
                                <fo:list-block provisional-distance-between-starts="2mm">
                                    <xsl:for-each select="INFO">
                                    <xsl:for-each select="LIST">
                                    <xsl:if test="@type='list' and ./INFO">
                                        <fo:list-item>
                                          <fo:list-item-label end-indent="label-end()" text-align="start">
                                            <fo:block font-size="9pt" text-align="left" font-family="arial">•</fo:block>
                                          </fo:list-item-label>
                                          <fo:list-item-body start-indent="body-start()" text-align="start">
                                            <fo:block font-size="9pt" text-align="left" font-family="arial">
                                                <xsl:value-of select="."/>
                                            </fo:block>
                                          </fo:list-item-body>
                                        </fo:list-item>
                                        </xsl:if>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </fo:list-block>
                                </xsl:if>
                            </xsl:for-each>
                            <xsl:for-each select="FILE">
                                <fo:block>
                                    <fo:external-graphic content-width="scale-down-to-fit" inline-progression-dimension.maximum="100%" src="{concat('url(file:D:///Tomcat/xsl/health/xml/docs/',$filename,')')}"/>
                                </fo:block>
                            </xsl:for-each>
                        </xsl:for-each>
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block></fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-body>
        </fo:table>
    </xsl:for-each>


    <!-- For Each Table of this product-->
    <!-- First the TOP ROW of the Header of the table-->
    <xsl:for-each select="TABLES/TABLE">
        <!-- new table, new page break-->
        <fo:table table-layout="fixed" width="100%" space-before="5pt">
            <fo:table-column column-width="30mm"/>
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell border-collapse="collapse">
                        <fo:block break-before="page"></fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-body>
        </fo:table>
        <xsl:variable name="pin" select="NAME"></xsl:variable>
        <xsl:variable name="countcol" select="COLUMNS">
        </xsl:variable>
        <xsl:variable name="columnum" select="TABLEHEADERFOOTER/HEADER/ROWS/row/col">
        </xsl:variable>
        <xsl:choose>
        <xsl:when test="contains($pin,'031')">
            <fo:block space-after="10pt" font-size="10pt" text-align="left" font-family="arial" color="#113488">
                Ευελιξία Επιλογών 
            </fo:block>
            <fo:block font-size="9pt" text-align="left" font-family="arial" color="black">
                some more text goes here
            </fo:block>
        </xsl:when>
        </xsl:choose>
        <!-- === BEGIN: set up variables === -->
        <xsl:variable name="varNormalBGColor">#e7e8ed</xsl:variable>
        <xsl:variable name="varAccentBGColor">#cccdda</xsl:variable>
        <xsl:variable name="varWhiteBGColor">#ffffff</xsl:variable>


        <!-- === END: set up variables === -->

        <!-- ALL IN ONE TABLE and the ROWS of the Header of the table (column labels)-->
        <!-- i am trying to do it dynamicaly and not whith if (size is dynamic 189/colunum-->
        <fo:table table-layout="fixed" width="100%" space-before="20pt" space-after="10pt">
            <xsl:for-each select="TABLEHEADERFOOTER/HEADER/ROWS/row/label">
                <fo:table-column column-width="{$columnum }"/>
            </xsl:for-each>
            <!-- now the column labels-->
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell padding-right="0mm" padding-top="0mm" padding-bottom="0mm" number-columns-spanned="{$countcol}">
                        <xsl:for-each select="TABLEHEADERFOOTER/HEADER/TOPROW">
                            <fo:block space-after="0pt" font-size="9pt" text-align="center" font-family="arial" color="white" background-color="#113388">
                                <xsl:value-of select="."/>
                            </fo:block>
                        </xsl:for-each>
                    </fo:table-cell>
                </fo:table-row>
                <!-- MY DATA ROWS -->
                <xsl:for-each select="TABLEHEADERFOOTER/HEADER/ROWS/row">
                    <fo:table-row>
                        <xsl:for-each select="label">
                        <xsl:choose>
                            <xsl:when test="@colspan">
                            <xsl:variable name="varcountcol">
                            <xsl:value-of select="@colspan"/>
                            </xsl:variable>
                                <fo:table-cell number-columns-spanned="{$varcountcol}" padding-right="0mm" padding-top="0mm" padding-bottom="0mm" background-color="#cccdda" border="1pt solid white">
                                    <fo:block space-after="0pt" font-size="6pt" text-align="center" font-family="arial" color="black">
                                        <xsl:value-of select="."/>
                                    </fo:block>
                                </fo:table-cell>
                            </xsl:when>
                            <xsl:otherwise>
                                <fo:table-cell padding-right="0mm" padding-top="0mm" padding-bottom="0mm" background-color="#cccdda" border="1pt solid white">
                                    <fo:block space-after="0pt" font-size="6pt" text-align="center" font-family="arial" color="black">
                                        <xsl:value-of select="."/>
                                    </fo:block>
                                </fo:table-cell>
                            </xsl:otherwise>
                        </xsl:choose>
                        </xsl:for-each>
                    </fo:table-row>
                </xsl:for-each>

                <!-- additional rows (not new TABLE) with COLUMNS (details)-->

                <xsl:for-each select="ELEMENTS/rows/row">
                    <fo:table-row>

                        <xsl:if test="ROW_TYPE='TOTAL'">
                            <xsl:for-each select="colvalue">
                                <fo:table-cell padding-right="0mm" padding-top="2mm" padding-bottom="0mm" border="1pt solid white" background-color="#e7e8ed">
                                    <fo:block font-size="8pt" text-align="right" font-family="arialbd" color="#113388">
                                        <xsl:value-of select="."/>
                                    </fo:block>
                                </fo:table-cell>
                            </xsl:for-each>
                        </xsl:if>
                        <xsl:if test="ROW_TYPE='TOTAL1'">
                            <!--<xsl:for-each select="POSO_CHR_1">-->
                                <fo:table-cell number-columns-spanned="{$countcol}"  padding-right="0mm" padding-top="2mm" padding-bottom="0mm"  background-color="#e7e8ed">
                                    <fo:block font-size="7pt" text-align="left" font-family="arialbd" color="black">
                                        <xsl:value-of select="colvalue" /> &#160; <xsl:value-of select="POSO_CHR_1"/>
                                    </fo:block>
                                </fo:table-cell>
                            <!--</xsl:for-each>-->
                        </xsl:if>

                        <xsl:if test="ROW_TYPE='DETAIL'">
                            <xsl:variable name="row" select="position()"/>
                            <xsl:for-each select="colvalue">
                            <xsl:variable name="colnumber" select="position()"/>
                                <fo:table-cell padding-right="0mm" padding-top="0.5mm" padding-bottom="0mm" border="1pt solid white">
                                    <xsl:attribute name="background-color">
                                        <xsl:choose>
                                        <xsl:when test="contains($pin,'031')">
                                            <xsl:value-of select="$varWhiteBGColor"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                        <xsl:choose>
                                            <xsl:when test="($row mod 2) = 0">
                                                <xsl:value-of select="$varAccentBGColor"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="$varNormalBGColor"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:attribute>
                                    <xsl:choose>
                                        <xsl:when test="contains($pin,'031')">
                                        <xsl:choose>
                                            <xsl:when test="$colnumber  = 2">
                                            <fo:block font-size="9pt" text-align="right" font-family="arial" color="black" margin-right="60mm" padding-top="10pt" padding-bottom="5pt">
                                            <xsl:value-of select="."/> €
                                            </fo:block>
                                            </xsl:when>
                                            <xsl:otherwise>
                                            <fo:block font-size="9pt" text-align="left" font-family="arial" color="black" padding-top="10pt" padding-bottom="5pt">
                                            <xsl:value-of select="."/>
                                            </fo:block>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <fo:block font-size="7pt" text-align="right" font-family="arial" color="black">
                                            <xsl:value-of select="."/>
                                            </fo:block>
                                        </xsl:otherwise>
                                    </xsl:choose>

                                </fo:table-cell>
                            </xsl:for-each>
                        </xsl:if>

                    </fo:table-row>
                </xsl:for-each>
            </fo:table-body>
        </fo:table>





        <!-- now for the footer of the freaking thing-->
        <fo:table table-layout="fixed" width="100%" space-before="5pt" space-after="10pt">
            <xsl:for-each select="TABLEHEADERFOOTER/FOOTER/ROWS/row/label">
                <fo:table-column column-width="proportional-column-width(1)"/>
            </xsl:for-each>
            <!-- now the column labels-->
            <fo:table-body>
                <xsl:for-each select="TABLEHEADERFOOTER/FOOTER/ROWS/row">
                    <fo:table-row>
                        <xsl:for-each select="label">
                            <fo:table-cell padding-right="0mm" padding-top="0mm" padding-bottom="0mm">
                                <fo:block space-after="0pt" font-size="8pt" text-align="center" font-family="arial" color="black" background-color="lightgrey">
                                    <xsl:value-of select="."/>
                                </fo:block>
                            </fo:table-cell>
                        </xsl:for-each>
                    </fo:table-row>
                </xsl:for-each>
            </fo:table-body>
        </fo:table>
        <!-- footer has an additional DATA tag-->
        <fo:table table-layout="fixed" width="100%">
            <fo:table-column column-width="proportional-column-width(1)"/>
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell padding-right="0mm" padding-top="0mm" padding-bottom="0mm">
                        <fo:block space-after="0pt" font-size="8pt" text-align="left" font-family="arial" color="black" background-color="white">
                            <xsl:value-of select="TABLEHEADERFOOTER/FOOTER/DATA/HEADER"/>
                        </fo:block>
                    </fo:table-cell>
                </fo:table-row>

                <xsl:for-each select="TABLEHEADERFOOTER/FOOTER/DATA/LINE">
                    <fo:table-row>
                        <fo:table-cell padding-right="0mm" padding-top="0mm" padding-bottom="0mm">
                            <fo:block space-after="0pt" font-size="8pt" text-align="left" font-family="arial" color="black" background-color="white">
                                <xsl:value-of select="."/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </xsl:for-each>
            </fo:table-body>
        </fo:table>

    </xsl:for-each>
                            <fo:block id="terminator"/>

</xsl:template>

然而fop 0.20.5并非如此。就好像它看不到嵌入式XML一样,好像我无法访问它为什么会发生这种情况的任何想法?同样在0.20.5上,页边距似乎不适合页脚,因为第一页的页脚出现在第二个空页面的顶部(再次这在fop 1.1上工作正常)很抱歉,如果这是一个愚蠢的问题但是我缺乏这方面的经验,到目前为止我还没有找到任何解决方案......

            <!-- rest pages Footer -->
        <fo:static-content flow-name="xsl-region-after" space-before="15pt">
            <fo:block font-size="9pt" font-family="arial" space-before="15pt">
                <fo:leader leader-length="100%" leader-pattern="rule" rule-style="solid" rule-thickness="0.1mm" color="black"/>
            </fo:block>
            <fo:table table-layout="fixed" width="185mm">
                <fo:table-column column-width="105mm"/>
                <fo:table-column column-width="80mm"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell>
                            <fo:block text-align="end" font-size="7pt" font-family="arial">ΣΕΛΙΔΑ <fo:page-number/>/<fo:page-number-citation ref-id="terminator"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-family="arial" font-size="7pt"></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:static-content>

0 个答案:

没有答案