需要动态更改simple-page-master的主名称

时间:2017-08-11 17:47:53

标签: xslt xsl-fo apache-fop

我有一个xml文档,如下所示。每个重复文档都是PDF文件中的页面

<AFPXMLFile>
    <docs>
      <regList>
           <region>1</region>
           <secList>
               <col>1</col>
               <lines></lines>
          </secList>
     </regList>
     <regList>
         <region>2</region>
         <secList>
               <col>2</col>
               <lines>
                  <line>IBM BELGIUM xxx</line>
                  <line>xxxxxx</line>
                  <line>xxxx</line>
              </lines>
         </secList>
     </regList>
     <regList></regList>
     <regList></regList>
  </docs>
  <docs></docs>
 </AFPXMLFile>

我的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">

<xsl:template match="AFPXMLFile">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-width="21cm" page-height="29.7cm"  margin-top="1.27cm" margin-bottom="1.27cm" margin-left="1.75cm" master-name="A4">
  <fo:region-body   margin-top="1mm" margin-bottom="1mm"/>
  <fo:region-before extent="0mm"/>
  <fo:region-after  extent="0mm"/>
  <fo:region-start  writing-mode="tb-rl" precedence="true" extent="10mm" />  
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4" font-family="sans-serif">
<xsl:for-each select="docs">
    <xsl:for-each select="./regList">
        <xsl:choose>
            <xsl:when test="region = 1">
               <fo:static-content flow-name="xsl-region-before">
                    <xsl:for-each select="./secList/lines">
                        <xsl:for-each select="node()">
                            <fo:block font-size="8pt" color="purple">
                                <xsl:value-of select="."/>
                           </fo:block>                                 
                        </xsl:for-each>
                     </xsl:for-each>
                </fo:static-content>
            </xsl:when>
            <xsl:when test="region = 2">
               <fo:static-content flow-name="xsl-region-start">
                    <xsl:for-each select="./secList/lines">
                        <xsl:for-each select="node()">
                                <fo:block font-size="4pt" padding-before="4pt" text-align="left" color="green">
                                    <xsl:value-of select="."/>
                                </fo:block> 
                        </xsl:for-each>
                     </xsl:for-each>
                 </fo:static-content>    
            </xsl:when>
            <xsl:when test="region = 3">
                <fo:static-content flow-name="xsl-region-body">
                    <xsl:for-each select="./secList/lines">
                        <xsl:for-each select="node()">
                            <fo:block font-size="8pt" color="blue">
                                <xsl:value-of select="."/>
                            </fo:block>
                         </xsl:for-each>
                    </xsl:for-each>
                </fo:static-content>
            </xsl:when>
            <xsl:when test="region = 4">
               <fo:flow flow-name="xsl-region-after">
                    <xsl:for-each select="./secList">
                        <xsl:for-each select="./lines">
                            <xsl:for-each select="node()">
                                <fo:block font-size="8pt" color="orange">
                                    <xsl:value-of select="."/>
                               </fo:block>
                            </xsl:for-each>
                        </xsl:for-each>
                     </xsl:for-each>
               </fo:flow>      
            </xsl:when>  
        </xsl:choose>                        
    </xsl:for-each>
</xsl:for-each>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

当我运行转换时,我收到以下错误:

  

org.apache.fop.fo.ValidationException:For&#34; fo:page-sequence&#34;,&#34; fo:static-content&#34;必须在&#34; fo:flow&#34;之前宣布! (没有上下文信息)

我怀疑这是因为它正在为每个页面重复静态内容区域。所以我相信我需要为每个页面更改simple-page-master:master-name 我需要帮助。

0 个答案:

没有答案