2013-07-03 109 views
4

我目前有一個XSL文件,用於將XML轉換爲FO格式(XSL-FO)。 唯一的問題是頁腳。 我有要求顯示從每個頁面的頁腳到其他頁面之一的文本參考。這意味着什麼我需要使頁腳文本動態。 例如,這裏的每個頁面的一些抽象的文字:靜態內容但動態內容的XSL-FO頁腳?

page 1: Topic A 
page 2: Topic B 
page 3: Topic C, Subtopic of A 
page 4: Topic D, Subtopic of A 
page 5: Topic E, Subtopic of B 

暢想「副標題」一部分頁腳來顯示每個頁面。

考慮下面的XML:

<DATA_DS> 
    <LIST_ITEMS> 
     <ITEMS> 
      <isChild>0</isChild> 
      <myvalue>abc</myvalue> 
      <isLastChild>0</isLastChild> 
     </ITEMS> 
     <ITEMS> 
      <isChild>1</isChild> 
      <myvalue>def</myvalue> 
      <isLastChild>0</isLastChild> 
     </ITEMS> 
     <ITEMS> 
      <isChild>1</isChild> 
      <myvalue>ghi</myvalue> 
      <isLastChild>0</isLastChild> 
     </ITEMS> 
     <ITEMS> 
      <isChild>1</isChild> 
      <myvalue>xyz</myvalue> 
      <isLastChild>1</isLastChild> 
     </ITEMS>   
    </LIST_ITEMS> 
</DATA_DS> 

這XSL:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="/"> 
    <fo:root> 
     <fo:layout-master-set> 
      <fo:simple-page-master master-name="parentLOBPage-master" page-width="11in" page-height="8.5in" margin-left="1.3in" margin-right="0.65in" margin-top="0.35in" margin-bottom="0.35in"> 
       <fo:region-body region-name="body" margin-top="0.5in" margin-right="0.65in"/> 
       <fo:region-after region-name="footer" extent="14mm" /> 
      </fo:simple-page-master> 

      <fo:simple-page-master master-name="childLOBPage-master" page-width="11in" page-height="8.5in" margin-left="1.3in" margin-right="0.65in" margin-top="0.35in" margin-bottom="0.35in"> 
       <fo:region-body region-name="body" margin-top="0.5in" margin-right="0.65in"/> 
       <fo:region-after region-name="footer" extent="14mm"/> 
      </fo:simple-page-master> 

      <fo:page-sequence-master master-name="parentLOBPage"> 
      <fo:repeatable-page-master-reference 
       master-reference="parentLOBPage-master"/> 
      </fo:page-sequence-master> 

      <fo:page-sequence-master master-name="childLOBPage"> 
      <fo:repeatable-page-master-reference 
       master-reference="childLOBPage-master"/> 
      </fo:page-sequence-master> 
     </fo:layout-master-set> 

      <xsl:apply-templates/> 

    </fo:root> 
    </xsl:template> 


    <xsl:template match="DATA_DS"> 
    <xsl:for-each-group select="LIST_ITEMS/ITEMS" 
         group-adjacent="isChild"> 

     <xsl:choose> 
     <xsl:when test="isChild = 0"> 
      <fo:page-sequence master-reference="parentLOBPage"> 


        <fo:static-content flow-name="footer"> 

          <fo:table width="100%" table-layout="fixed" margin-top="5mm"> 
           <fo:table-column column-width="80%"/> 
           <fo:table-column column-width="20%"/>        

           <fo:table-body> 
            <fo:table-row> 
            <fo:table-cell> 
              <fo:block text-align="left" font-family="Arial" font-size="7pt" font-weight="normal">parent footer</fo:block> 
            </fo:table-cell> 
            <fo:table-cell> 
             <fo:block text-align="right" font-family="Arial" font-size="7pt" font-weight="normal">Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page" /></fo:block> 
            </fo:table-cell> 
           </fo:table-row> 
          </fo:table-body> 
         </fo:table> 

         </fo:static-content>       

      <fo:flow flow-name="body"> 
       <xsl:for-each select="current-group()"> 
       <xsl:apply-templates select="."/> 
       </xsl:for-each> 
      </fo:flow> 
      </fo:page-sequence> 
     </xsl:when> 

     <xsl:otherwise> 
      <fo:page-sequence master-reference="childLOBPage"> 
        <fo:static-content flow-name="footer"> 
          <fo:table width="100%" table-layout="fixed" margin-top="5mm"> 
           <fo:table-column column-width="80%"/> 
           <fo:table-column column-width="20%"/>        

           <fo:table-body> 
            <fo:table-row> 
            <fo:table-cell> 
              <fo:block text-align="left" font-family="Arial" font-size="7pt" font-weight="normal">child footer: <xsl:value-of select="myvalue"/></fo:block> 
            </fo:table-cell> 
            <fo:table-cell> 
             <fo:block text-align="right" font-family="Arial" font-size="7pt" font-weight="normal">Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page" /></fo:block> 
            </fo:table-cell> 
           </fo:table-row> 
          </fo:table-body> 
         </fo:table> 

         </fo:static-content>       

      <fo:flow flow-name="body"> 

       <xsl:for-each select="current-group()"> 
       <xsl:apply-templates select="."/> 
       </xsl:for-each> 
       <fo:block id="last-page"/> 
      </fo:flow> 
      </fo:page-sequence> 
     </xsl:otherwise> 

     </xsl:choose> 
    </xsl:for-each-group> 
    </xsl:template> 


    <xsl:template match="ITEMS"> 

      <fo:table width="100%" table-layout="fixed" margin-top="5mm"> 
       <fo:table-column column-width="20%"/> 
       <fo:table-column column-width="80%"/>        

       <fo:table-body> 
        <fo:table-row> 
        <fo:table-cell> 
          <fo:block text-align="left" font-family="Arial" font-size="10pt" font-weight="bold">big table</fo:block> 
         </fo:table-cell> 
        <fo:table-cell> 
          <fo:block text-align="left" font-family="Arial" font-size="10pt" font-weight="bold">some stuff</fo:block> 
         </fo:table-cell>            
        </fo:table-row> 
       </fo:table-body> 
      </fo:table> 

     <xsl:if test="isChild = 1 and isLastChild = 0"> 
       <fo:block page-break-after="always"/> 
      </xsl:if> 

    </xsl:template> 
</xsl:stylesheet> 

因爲我將多數每一頁的FO內容:表,一些表溢出到2+頁面,我不能只在每個表格後放置「動態頁腳文本」,因爲它不會在每個頁面上顯示。

所以,我想我使用fo:static-content並不合適,即使它做我需要的動態顯示頁碼(即y的頁面x)。輸出結果顯示,對於每個頁腳頁面,顯示的值都是「def」,這是列表中的第一個「子」。所以,fo:static-content在第一次執行時自動填充,並且不會爲後續頁面更新...所以我的方法是錯誤的。我需要一些關於如何修改我的方法的指導...

關於如何讓頁腳以我需要的方式工作以滿足我的XSL-FO情況的任何建議? 謝謝...

回答

5

您的代碼不適合靜態內容中的動態內容。

您缺少的概念是您的頁腳需要「檢索標記」,您可以在流程中即時設置點。所有頁面的頁腳從頁面內容中檢索一個標記類,然後在流中的點處更改標記,並且檢索獲得最近的標記(或其他選項)。

所以,你只需要一個頁腳,它有你的「頁面x的位」,並且你需要包含一個檢索某個特定類的標記的頁腳。然後,在你的流程中,包括你的所有主題和子主題,當你到達每個主題和子主題的第一個項目時,用你想在頁腳中看到的文本定義一個標記。

的XSL-FO輸出的XSLT需要產生的線沿線的:

<fo:static-content> 
    ... page x of y stuff ... 
    <fo:retrieve-marker retrieve-class-name="topic"/> 
    </fo:static-content> 
    <fo:flow> 
    <fo:table> 
     ... 
     <fo:table-cell> 
     <fo:marker marker-class-name="topic">Topic A</fo:marker> 
     ... 
     <fo:table-cell> 
     <fo:marker marker-class-name="topic">Topic B</fo:marker> 
     ... 
     <fo:table-cell> 
     <fo:marker marker-class-name="topic">Topic C, Subtopic of A</fo:marker> 
     ... 
     <fo:table-cell> 
     <fo:marker marker-class-name="topic">Topic D, Subtopic of A</fo:marker> 
     ... 
     <fo:table-cell> 
     <fo:marker marker-class-name="topic">Topic E, Subtopic of B</fo:marker> 

我建議您查看標題爲「在靜態內容動態內容」開始免費的257頁上的框架「嘗試買」預覽我的PDF簿的:

http://www.CraneSoftwrights.com/training/#pfux

有細微差別,爲檢索和那些有描述,與圖中的標記的定位屬性。

+0

謝謝!標記功能是我正在尋找的... – Kevin