2017-09-28 54 views
3

我使用XSL-FO生成一些PDF文檔,並且有一些表可以跨越多個頁面。在這些情況下,我想要做的是在每個新頁面的開始處重複表格的標題,並在除第一頁之外的所有頁面上使用「(續)」標籤。XSL-FO繼續表頭

我的XSL代碼:

<xsl:template name="Tooling"> 
    <fo:table xsl:use-attribute-sets="tableDefaultLayout"> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-column column-width="74mm" /> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-header xsl:use-attribute-sets="categoryDefaultFont"> 
      <fo:table-row height="7.7mm" border="0pt solid black" display-align="before" text-align="start"> 
       <fo:table-cell number-columns-spanned="4" font-size="12pt"> 
        <fo:block margin-top="3mm"> 
         <fo:retrieve-table-marker retrieve-class-name="continued" 
      retrieve-position-within-table="first-starting" 
      retrieve-boundary-within-table="table-fragment"/> 
      &#x00A0; 
        </fo:block> 
       </fo:table-cell> 
      </fo:table-row> 
      <fo:table-row xsl:use-attribute-sets="defaultBodyRow" height="4.7mm" border="0pt solid black"> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Item No.</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Part No.</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Description</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Qty Reqd</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
      </fo:table-row> 
     </fo:table-header> 
     <fo:table-body xsl:use-attribute-sets="valueDefaultFont" font-size="8pt"> 
      <xsl:for-each select="1 to 50"> 
       <fo:table-row xsl:use-attribute-sets="defaultBodyRow" border="0pt solid black"> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:choose> 
           <xsl:when test="position()=1"> 
            <fo:marker marker-class-name="continued"> 
             <xsl:text>TOOLING:-</xsl:text> 
            </fo:marker> 
           </xsl:when> 
           <xsl:otherwise> 
            <fo:marker marker-class-name="continued"> 
             <xsl:text>TOOLING: (continued)</xsl:text> 
            </fo:marker> 
           </xsl:otherwise> 
          </xsl:choose> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
      </xsl:for-each> 
     </fo:table-body> 
    </fo:table> 
</xsl:template> 

而且FO產生:

<fo:table border-bottom="0.5pt solid black" border-collapse="collapse" border-left="1pt solid black" border-right="1pt solid black" border-top="0.5pt solid black" margin="0mm" padding="0mm" table-layout="fixed" width="100%"> 
       <fo:table-column column-width="37mm"/> 
       <fo:table-column column-width="37mm"/> 
       <fo:table-column column-width="74mm"/> 
       <fo:table-column column-width="37mm"/> 
       <fo:table-header font-family="sans-serif" font-size="10pt" font-weight="bold"> 
        <fo:table-row border="0pt solid black" display-align="before" height="7.7mm" text-align="start"> 
         <fo:table-cell font-size="12pt" number-columns-spanned="4"> 
          <fo:block margin-top="3mm"> 
           <fo:retrieve-table-marker retrieve-boundary-within-table="table-fragment" retrieve-class-name="continued" retrieve-position-within-table="first-starting"/> 
        
          </fo:block> 
         </fo:table-cell> 
        </fo:table-row> 
        <fo:table-row border="0pt solid black" display-align="center" height="4.7mm" keep-together.within-page="always" text-align="center"> 
         <fo:table-cell> 
          <fo:block>Item No.</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>Part No.</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>Description</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>Qty Reqd</fo:block> 
         </fo:table-cell> 
        </fo:table-row> 
       </fo:table-header> 
       <fo:table-body font-family="monospace" font-size="8pt" font-weight="normal"> 
        <fo:table-row border="0pt solid black" display-align="center" height="7.74mm" keep-together.within-page="always" text-align="center"> 
         <fo:table-cell> 
          <fo:block> 
           <fo:marker marker-class-name="continued">TOOLING:-</fo:marker>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
        </fo:table-row> 
        <fo:table-row border="0pt solid black" display-align="center" height="7.74mm" keep-together.within-page="always" text-align="center"> 
         <fo:table-cell> 
          <fo:block> 
           <fo:marker marker-class-name="continued">TOOLING: (continued)</fo:marker>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
         <fo:table-cell> 
          <fo:block>[email protected]</fo:block> 
         </fo:table-cell> 
        </fo:table-row> 

然後持續50行:正如你所看到的第一個具有標誌 「沺: - 」 和所有其他人有一個標記「工具:(續)」,這是我想要的。

我的問題是,我似乎無法使fo:retrieve-table-marker對象正常工作:我嘗試過多次組合「檢索位置」和「檢索邊界」屬性,但每次我的標題的第一行總是空白,在第一頁或其他頁面上。

如果有人能向我解釋我對這些「fo:retrieve-table-marker」和「fo:marker」對象做了什麼錯誤,那將是一個真正的幫助,我一直在努力解決這個問題現在幾天。

+0

我前一陣子也有類似的問題(試圖之前檢索標記第一個fo:marker事件),並在我的第一個檢索標記之前放置一個額外的fo:marker實例來解決它。不過它不應該工作。 – Hobbes

+0

你已經設置了'table-omit-header-at-break =「true」'。由於標記只能用於表頭,如果您不要求顯示錶頭,** Continued **不會出現。否則,你的其他代碼是正確的。 – potame

+0

對不起,「table-omit-header-at-break」是一個複製/粘貼錯誤,我試圖添加這個屬性來看看它做了什麼,但它實際上與我的問題沒有關係。 @霍布斯感謝您的提示,我要試一試 – eipiplusun

回答

0

您已設置table-omit-header-at-break="true"。由於標記只能用於表格標題中,如果您不要求顯示錶格標題,則不會顯示續前。否則,你的其他代碼是正確的。

因此我如下會糾正你的XSLT代碼:

首先,刪除<xsl:attribute name="table-omit-header-at-break">true</xsl:attribute>可能在其他地方的樣式表可以發現,<xsl:attribute-set name="tableDefaultLayout">定義範圍內。

然後修改您的模板,像這樣:

<xsl:template name="Tooling"> 
    <fo:table xsl:use-attribute-sets="tableDefaultLayout"> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-column column-width="74mm" /> 
     <fo:table-column column-width="37mm" /> 
     <fo:table-header xsl:use-attribute-sets="categoryDefaultFont"> 
      <fo:table-row height="7.7mm" border="0pt solid black" display-align="before" text-align="start"> 
       <fo:table-cell number-columns-spanned="4" font-size="12pt"> 
        <fo:block margin-top="3mm"> 
         <fo:retrieve-table-marker retrieve-class-name="continued" 
      retrieve-position-within-table="first-starting" 
      retrieve-boundary-within-table="table-fragment"/> 
      &#x00A0; 
        </fo:block> 
       </fo:table-cell> 
      </fo:table-row> 
     </fo:table-header> 
     <fo:table-body xsl:use-attribute-sets="valueDefaultFont" font-size="8pt"> 
      <fo:table-row xsl:use-attribute-sets="defaultBodyRow" height="4.7mm" border="0pt solid black"> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Item No.</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Part No.</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Description</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
       <fo:table-cell> 
        <fo:block> 
         <xsl:text>Qty Reqd</xsl:text> 
        </fo:block> 
       </fo:table-cell> 
      </fo:table-row> 
      <xsl:for-each select="1 to 50"> 
       <fo:table-row xsl:use-attribute-sets="defaultBodyRow" border="0pt solid black"> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:choose> 
           <xsl:when test="position()=1"> 
            <fo:marker marker-class-name="continued"> 
             <xsl:text>TOOLING:-</xsl:text> 
            </fo:marker> 
           </xsl:when> 
           <xsl:otherwise> 
            <fo:marker marker-class-name="continued"> 
             <xsl:text>TOOLING: (continued)</xsl:text> 
            </fo:marker> 
           </xsl:otherwise> 
          </xsl:choose> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
        <fo:table-cell> 
         <fo:block> 
          <xsl:text>[email protected]</xsl:text> 
         </fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
      </xsl:for-each> 
     </fo:table-body> 
    </fo:table> 
</xsl:template> 
+0

對不起,「table-omit-header-at-break」屬性是一個複製/粘貼錯誤,我將其刪除,但它並沒有改變我的問題:我的標題的第二行(「商品編號」,「零件編號」等)出現在每個頁面上(這是我想要的,所以我不能將它移動到身體上,因爲您告訴我要做),但應該是「工具:[(續)]」的第一行實際上只是空白。 – eipiplusun

0

作爲替代每一行中產生fo:marker

<fo:table-header xsl:use-attribute-sets="categoryDefaultFont"> 
    <fo:table-row height="7.7mm" border="0pt solid black" 
        display-align="before" text-align="start"> 
     <fo:table-cell number-columns-spanned="4" font-size="12pt"> 
      <fo:block margin-top="3mm">TOOLING:-<fo:retrieve-table-marker 
        retrieve-class-name="continued" 
        retrieve-position-within-table="last-starting"/> 
      </fo:block> 
     </fo:table-cell> 
    </fo:table-row> 
    ... 
</fo:table-header> 
<fo:table-body xsl:use-attribute-sets="valueDefaultFont" font-size="8pt"> 
    <fo:marker marker-class-name="continued" /> 
    <fo:marker marker-class-name="continued"> (continued)</fo:marker> 
    <xsl:for-each select="1 to 50"> 
     <fo:table-row xsl:use-attribute-sets="defaultBodyRow" 
         border="0pt solid black"> 
    ... 
+0

我看到它是如何減弱我的代碼,但它並沒有解決我的問題。 :/ – eipiplusun

+0

它適用於AH Formatter V6.5。你使用什麼格式化程序? –

+0

對不起,很長時間以來,我不得不問一些同事。所以碰巧我們使用了一個稱爲FPC的特殊格式化器,它可以識別'fo:marker'標記,但忽略它們。最終我們在fo:table標記中找到了一個'fpc:table-omit-header-at-start =「true」'屬性,這使得標題出現在除第一頁以外的每一頁上,並允許我們爲第一頁添加一個特定的標題,作爲正文的第一行。 無論如何,問題解決了,抱歉花了你的時間,並感謝答覆。 – eipiplusun