从fop-0.95升级到fop-2.3

时间:2019-02-27 21:11:39

标签: xslt xslt-1.0 xsl-fo apache-fop

我是XSLT FO世界的新手,遇到了一个问题。我的XSLT与fop-0.95处理器配合使用并生成PDF,但是升级到fop-2.3之后,它使我的第一页空白,并从第二页开始PDF正文(我的PDF的标题出现了在第一页上可以)。

我弄清楚问题出在哪里,这是因为我在“ fo:layout-master-set”(“ fo:layout-master-set”)中的“ fo:region-body”标签中将margin-top值设置为3英寸请参阅截图)。我必须将margin-top从3英寸更改为2.5英寸,以使PDF主体看起来像使用fop-0.95时的样子。

<?xml version="1.0" encoding="UTF-8"?>
<!--Designed and generated by Altova StyleVision Enterprise Edition 2013 (x64) - see http://www.altova.com/stylevision for more information.-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:altova="http://www.altova.com" xmlns:altovaext="http://www.altova.com/xslt-extensions" xmlns:clitype="clitype" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:ix="http://www.xbrl.org/2008/inlineXBRL" xmlns:java="java" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:sps="http://www.altova.com/StyleVision/user-xpath-functions" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" exclude-result-prefixes="altova altovaext clitype fn iso4217 ix java link sps xbrldi xbrli xlink xs xsi">
    <xsl:output version="1.0" method="xml" encoding="UTF-8" indent="no"/>
    <xsl:param name="SV_OutputFormat" select="'PDF'"/>
    <xsl:variable name="XML" select="/"/>
    <xsl:variable name="fo:layout-master-set">
        <fo:layout-master-set>
            <fo:simple-page-master master-name="page-master-0-even" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
                <fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
                <fo:region-before region-name="even-page-header" overflow="hidden" extent="0.45in"/>
                <fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="page-master-0-odd" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
                <fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
                <fo:region-before region-name="odd-page-header" overflow="hidden" extent="0.45in"/>
                <fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="page-master-0-even-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
                <fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
                <fo:region-before region-name="even-page-header-first" overflow="hidden" extent="3in"/>
                <fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="page-master-0-odd-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
                <fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
                <fo:region-before region-name="odd-page-header-first" overflow="hidden" extent="3in"/>
                <fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="page-master-0">
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference master-reference="page-master-0-even-first" odd-or-even="even" page-position="first"/>
                    <fo:conditional-page-master-reference master-reference="page-master-0-odd-first" odd-or-even="odd" page-position="first"/>
                    <fo:conditional-page-master-reference master-reference="page-master-0-even" odd-or-even="even"/>
                    <fo:conditional-page-master-reference master-reference="page-master-0-odd" odd-or-even="odd"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>
    </xsl:variable>
    <xsl:variable name="altova:nPxPerIn" select="96"/>
    <xsl:template match="/">
        <fo:root>
            <xsl:copy-of select="$fo:layout-master-set"/>
            <fo:declarations>
                <x:xmpmeta xmlns:x="adobe:ns:meta/">
                    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
                        <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
                            <xmp:CreatorTool>Altova StyleVision Enterprise Edition 2013 (x64) (http://www.altova.com)</xmp:CreatorTool>
                        </rdf:Description>
                    </rdf:RDF>
                </x:xmpmeta>
            </fo:declarations>
            <fo:page-sequence force-page-count="no-force" master-reference="page-master-0" initial-page-number="auto" format="1">
                <fo:static-content flow-name="odd-page-header-first">
                    <fo:block-container overflow="hidden" display-align="before">
                        <fo:block>
                            <xsl:for-each select="$XML">
                                <xsl:for-each select="DOCUMENT">
                                    <xsl:for-each select="DATA">
                                        <xsl:for-each select="STRUCT">
                                            <xsl:for-each select="FIELD[FNAME=&apos;nfHeaderDtls&apos;]">
                                                <xsl:for-each select="STRUCT">
                                                    <fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
                                                        <fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
                                                            <fo:block>
                                                                <xsl:for-each select="FIELD[FNAME=&apos;Name&apos;]">
                                                                    <xsl:for-each select="VALUE">
                                                                        <xsl:variable name="value-of-template_1">
                                                                            <xsl:apply-templates/>
                                                                        </xsl:variable>
                                                                        <xsl:choose>
                                                                            <xsl:when test="contains(string($value-of-template_1),'&#x200B;')">
                                                                                <fo:block>
                                                                                    <xsl:copy-of select="$value-of-template_1"/>
                                                                                </fo:block>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <fo:inline>
                                                                                    <xsl:copy-of select="$value-of-template_1"/>
                                                                                </fo:inline>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </xsl:for-each>
                                                                </xsl:for-each>
                                                                <fo:block/>
                                                            </fo:block>
                                                        </fo:block-container>
                                                    </fo:block-container>
                                                </xsl:for-each>
                                            </xsl:for-each>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="even-page-header-first">
                    <fo:block-container overflow="hidden" display-align="before">
                        <fo:block>
                            <xsl:for-each select="$XML">
                                <xsl:for-each select="DOCUMENT">
                                    <xsl:for-each select="DATA">
                                        <xsl:for-each select="STRUCT">
                                            <xsl:for-each select="FIELD[FNAME=&apos;nfHeaderDtls&apos;]">
                                                <xsl:for-each select="STRUCT">
                                                    <fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
                                                        <fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
                                                            <fo:block>
                                                                <xsl:for-each select="FIELD[FNAME=&apos;Name&apos;]">
                                                                    <xsl:for-each select="VALUE">
                                                                        <xsl:variable name="value-of-template_1">
                                                                            <xsl:apply-templates/>
                                                                        </xsl:variable>
                                                                        <xsl:choose>
                                                                            <xsl:when test="contains(string($value-of-template_1),'&#x200B;')">
                                                                                <fo:block>
                                                                                    <xsl:copy-of select="$value-of-template_1"/>
                                                                                </fo:block>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <fo:inline>
                                                                                    <xsl:copy-of select="$value-of-template_1"/>
                                                                                </fo:inline>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </xsl:for-each>
                                                                </xsl:for-each>
                                                                <fo:block/>
                                                            </fo:block>
                                                        </fo:block-container>
                                                    </fo:block-container>
                                                </xsl:for-each>
                                            </xsl:for-each>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="odd-page-header">
                    <fo:block-container overflow="hidden" display-align="before">
                        <fo:block>
                            <xsl:for-each select="$XML">
                                <xsl:for-each select="DOCUMENT">
                                    <xsl:for-each select="DATA">
                                        <xsl:for-each select="STRUCT">
                                            <xsl:for-each select="FIELD[FNAME=&apos;nfHeaderDtls&apos;]">
                                                <xsl:for-each select="STRUCT">
                                                    <fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
                                                        <fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
                                                            <fo:block>
                                                                <fo:inline>
                                                                    <xsl:text>Identifier: </xsl:text>
                                                                </fo:inline>
                                                                <xsl:for-each select="FIELD[FNAME=&apos;caseReference&apos;]">
                                                                    <xsl:for-each select="VALUE">
                                                                        <xsl:variable name="value-of-template_27">
                                                                            <xsl:apply-templates/>
                                                                        </xsl:variable>
                                                                        <xsl:choose>
                                                                            <xsl:when test="contains(string($value-of-template_27),'&#x200B;')">
                                                                                <fo:block>
                                                                                    <xsl:copy-of select="$value-of-template_27"/>
                                                                                </fo:block>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <fo:inline>
                                                                                    <xsl:copy-of select="$value-of-template_27"/>
                                                                                </fo:inline>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </xsl:for-each>
                                                                </xsl:for-each>
                                                            </fo:block>
                                                        </fo:block-container>
                                                    </fo:block-container>
                                                </xsl:for-each>
                                            </xsl:for-each>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="even-page-header">
                    <fo:block-container overflow="hidden" display-align="before">
                        <fo:block>
                            <xsl:for-each select="$XML">
                                <xsl:for-each select="DOCUMENT">
                                    <xsl:for-each select="DATA">
                                        <xsl:for-each select="STRUCT">
                                            <xsl:for-each select="FIELD[FNAME=&apos;nfHeaderDtls&apos;]">
                                                <xsl:for-each select="STRUCT">
                                                    <fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
                                                        <fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
                                                            <fo:block>
                                                                <fo:inline>
                                                                    <xsl:text>Identifier: </xsl:text>
                                                                </fo:inline>
                                                                <xsl:for-each select="FIELD[FNAME=&apos;caseReference&apos;]">
                                                                    <xsl:for-each select="VALUE">
                                                                        <xsl:variable name="value-of-template_27">
                                                                            <xsl:apply-templates/>
                                                                        </xsl:variable>
                                                                        <xsl:choose>
                                                                            <xsl:when test="contains(string($value-of-template_27),'&#x200B;')">
                                                                                <fo:block>
                                                                                    <xsl:copy-of select="$value-of-template_27"/>
                                                                                </fo:block>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <fo:inline>
                                                                                    <xsl:copy-of select="$value-of-template_27"/>
                                                                                </fo:inline>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </xsl:for-each>
                                                                </xsl:for-each>
                                                            </fo:block>
                                                        </fo:block-container>
                                                    </fo:block-container>
                                                </xsl:for-each>
                                            </xsl:for-each>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="odd-page-footer">
                    <fo:block-container height="0.45in" overflow="hidden" display-align="after">
                        <fo:block>
                            <fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
                                <fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
                                    <fo:block>
                                        <fo:inline>
                                            <xsl:text>My Test Form</xsl:text>
                                        </fo:inline>
                                        <fo:block/>
                                        <fo:inline>
                                            <xsl:text>Test Text</xsl:text>
                                        </fo:inline>
                                    </fo:block>
                                </fo:block-container>
                                <fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
                                    <fo:block>
                                        <fo:inline font-weight="bold">
                                            <xsl:text>Page: </xsl:text>
                                        </fo:inline>
                                        <fo:page-number font-weight="bold"/>
                                        <fo:inline font-weight="bold">
                                            <xsl:text> of </xsl:text>
                                        </fo:inline>
                                        <fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
                                    </fo:block>
                                </fo:block-container>
                            </fo:block-container>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:static-content flow-name="even-page-footer">
                    <fo:block-container height="0.45in" overflow="hidden" display-align="after">
                        <fo:block>
                            <fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
                                <fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
                                    <fo:block>
                                        <fo:inline>
                                            <xsl:text>My Test Form</xsl:text>
                                        </fo:inline>
                                        <fo:block/>
                                        <fo:inline>
                                            <xsl:text>Test Text</xsl:text>
                                        </fo:inline>
                                    </fo:block>
                                </fo:block-container>
                                <fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
                                    <fo:block>
                                        <fo:inline font-weight="bold">
                                            <xsl:text>Page: </xsl:text>
                                        </fo:inline>
                                        <fo:page-number font-weight="bold"/>
                                        <fo:inline font-weight="bold">
                                            <xsl:text> of </xsl:text>
                                        </fo:inline>
                                        <fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
                                    </fo:block>
                                </fo:block-container>
                            </fo:block-container>
                        </fo:block>
                    </fo:block-container>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <xsl:for-each select="$XML">
                            <xsl:for-each select="DOCUMENT">
                                <xsl:for-each select="DATA">
                                    <xsl:for-each select="STRUCT">
                                        <fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="7.040000in" overflow="hidden">
                                            <fo:block-container absolute-position="absolute" font-family="Arial" font-size="13pt" font-weight="bold" height="0.28in" left="0in" text-align="center" top="0in" width="7.46in" overflow="hidden">
                                                <fo:block>
                                                    <fo:inline>
                                                        <xsl:text>Form Body Starts Here </xsl:text>
                                                    </fo:inline>
                                                    <xsl:for-each select="FIELD[FNAME=&apos;nfFormTitle&apos;]">
                                                        <xsl:for-each select="VALUE">
                                                            <xsl:variable name="value-of-template_28">
                                                                <xsl:apply-templates/>
                                                            </xsl:variable>
                                                            <xsl:choose>
                                                                <xsl:when test="contains(string($value-of-template_28),'&#x200B;')">
                                                                    <fo:block>
                                                                        <xsl:copy-of select="$value-of-template_28"/>
                                                                    </fo:block>
                                                                </xsl:when>
                                                                <xsl:otherwise>
                                                                    <fo:inline>
                                                                        <xsl:copy-of select="$value-of-template_28"/>
                                                                    </fo:inline>
                                                                </xsl:otherwise>
                                                            </xsl:choose>
                                                        </xsl:for-each>
                                                    </xsl:for-each>
                                                    <fo:inline>
                                                        <xsl:text> Test Test</xsl:text>
                                                    </fo:inline>
                                                </fo:block>
                                            </fo:block-container>

                                        </fo:block-container>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </xsl:for-each>
                        </xsl:for-each>

                    </fo:block>
                    <fo:block id="SV_RefID_PageTotal"/>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <xsl:template name="altova:double-backslash">
        <xsl:param name="text"/>
        <xsl:param name="text-length"/>
        <xsl:variable name="text-after-bs" select="substring-after($text, '\')"/>
        <xsl:variable name="text-after-bs-length" select="string-length($text-after-bs)"/>
        <xsl:choose>
            <xsl:when test="$text-after-bs-length = 0">
                <xsl:choose>
                    <xsl:when test="substring($text, $text-length) = '\'">
                        <xsl:value-of select="concat(substring($text,1,$text-length - 1), '\\')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$text"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat(substring($text,1,$text-length - $text-after-bs-length - 1), '\\')"/>
                <xsl:call-template name="altova:double-backslash">
                    <xsl:with-param name="text" select="$text-after-bs"/>
                    <xsl:with-param name="text-length" select="$text-after-bs-length"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="altova:MakeValueAbsoluteIfPixels">
        <xsl:param name="sValue"/>
        <xsl:variable name="sBeforePx" select="substring-before($sValue, 'px')"/>
        <xsl:choose>
            <xsl:when test="$sBeforePx">
                <xsl:variable name="nLengthOfInteger">
                    <xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
                        <xsl:with-param name="sText" select="$sBeforePx"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:variable name="nPosOfInteger" select="string-length($sBeforePx) - $nLengthOfInteger + 1"/>
                <xsl:variable name="nValuePx" select="substring($sBeforePx, $nPosOfInteger)"/>
                <xsl:variable name="nValueIn" select="number($nValuePx) div number($altova:nPxPerIn)"/>
                <xsl:variable name="nLengthBeforeInteger" select="string-length($sBeforePx) - $nLengthOfInteger"/>
                <xsl:variable name="sRest">
                    <xsl:call-template name="altova:MakeValueAbsoluteIfPixels">
                        <xsl:with-param name="sValue" select="substring-after($sValue, 'px')"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="concat(substring($sBeforePx, 1, $nLengthBeforeInteger), string($nValueIn), 'in', $sRest)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$sValue"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="altova:GetCharCountOfIntegerAtEndOfString">
        <xsl:param name="sText"/>
        <xsl:variable name="sLen" select="string-length($sText)"/>
        <xsl:variable name="cLast" select="substring($sText, $sLen)"/>
        <xsl:choose>
            <xsl:when test="number($cLast) &gt;= 0 and number($cLast) &lt;= 9">
                <xsl:variable name="nResultOfRest">
                    <xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
                        <xsl:with-param name="sText" select="substring($sText, 1, $sLen - 1)"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="$nResultOfRest + 1"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>0</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

有人知道为什么会这样吗?
我有多个具有相同布局的PDF,因此如果我需要升级到fop-2.3,是否必须对所有PDF进行此更改?

编辑-1.感谢您的评论和回答。抱歉,我花了一段时间才回复,因为我正在努力批准发布此xslt。

2。我编辑了xslt,因为它太大而无法遵守该帖子的字数限制。但是它仍然具有所有重要部分,例如PDF正文的开头等。

XSLT Screenshot

1 个答案:

答案 0 :(得分:0)

对不起,但找出为什么同一软件的不同版本之间有所不同的最佳方法是浏览自较旧版本以来的发行说明。

FOP在其网站上有发行说明。当我确认这一点时,我在https://xmlgraphics.apache.org/fop/1.0/changes_1.0.html上找到了它,这可能就是您想要的:

  

启用宽松验证时,允许非零边框和页面区域上的填充。由LF承诺。

如果这是原因,那么解决方法是从margin-top中删除fo:simple-page-master。否则,恐怕还有很多发行说明供您浏览。