2014-09-24 68 views
1

我使用xsl fo和apache fop生成pdf文檔。我有不同的頁面序列(coverpage,toc,imprint和「主要內容」)。防止空白頁在最後一面在xsl fo

在我處理xml文件中的數據的主要內容中,它很好。

在主要內容開始時,我開始統計頁面並在底部/右側顯示。有了這個我有一個問題,它顯示「主要內容」之前的空白頁面,我可以通過在頁面序列中添加「force-page-count =」no-force「之前解決此問題。我具備的主要內容序列之後,空白頁,任何想法我怎麼能解決這個

之前主要內容頁序:

<fo:page-sequence master-reference="imprint" force-page-count="no-force"> 
... 
</fo:page-sequence> 

主要內容:

<fo:page-sequence master-reference="per-Gruppe" initial-page-number="1"> 
       <fo:static-content flow-name="header"> 
        <xsl:call-template name="doc-header" match=""/> 
        <fo:block/> 
       </fo:static-content> 
       <fo:static-content flow-name="footer"> 
        <xsl:call-template name="doc-footer"/> 
        <fo:block/> 
       </fo:static-content> 
       <fo:flow flow-name="xsl-region-body"> 
        <xsl:for-each select="//lb"> 
         <xsl:call-template name="Kapitel" select="name"/> 
         <xsl:for-each select="per-group/pe"> 
          <xsl:call-template name="st.Table" select="."/> 
         </xsl:for-each> 
         <xsl:for-each select="cu-group/cu"> 
          <xsl:call-template name="st.Table" select="."/> 
         </xsl:for-each> 
         <xsl:if test="position()=last()"> 
          <fo:block id="lastpage"/> 
         </xsl:if> 
        </xsl:for-each> 
       </fo:flow> 
      </fo:page-sequence> 

任何suggestio NS?

謝謝。

回答

2

好的,我解決了它。我做了以下步驟。

  1. 我把每個循環放在頁面序列之外。
  2. 然後我圍住序列與一個xsl:選擇,在xsl:選擇我檢查,結果我稱之爲模板頁面順序和位置
  3. - >「st.table」模板
  4. 在模板(st.table)我檢查結果,如果它是最後一個位置,我設置最後一頁,並且防止設置頁面中斷後的屬性(這就是爲什麼我在末尾得到空白頁的原因)

頁序:

<xsl:for-each select="//lb"> 
       <xsl:choose> 
        <xsl:when test="position() = 1"> 
         <fo:page-sequence master-reference="per-Gruppe" initial-page-number="1"> 
          ... 
         </fo:page-sequence> 
        </xsl:when> 
        <xsl:otherwise> 
         <fo:page-sequence master-reference="per-Gruppe"> 
          ... 
          <fo:flow flow-name="xsl-region-body"> 
           ... 
           <xsl:for-each select="cu-group/cu"> 
            <xsl:call-template name="st.Table" select="."> 
             <xsl:with-param name="last_pos" select="$last_pos" /> 
            </xsl:call-template> 
           </xsl:for-each> 
          </fo:flow> 
         </fo:page-sequence> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:for-each> 

模板:

<xsl:template name="st.Table" match="."> 
     <xsl:param name="last_pos" select="false()" /> 
     ... 
     <xsl:if test="$last_pos"> 
      <fo:block id="lastpage"/>  
     </xsl:if> 
     <xsl:if test="$last_pos=false()"> 
      <fo:block page-break-after="always" /> 
     </xsl:if> 
    </xsl:template>