2016-06-17 93 views
2

這是我前一段時間發佈的this question的後續問題。如何垂直填充表格?

我有以下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" exclude-result-prefixes="fo"> 
    <xsl:template match="barcode-list"> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     <fo:layout-master-set> 
     <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> 
      <fo:region-body/> 
     </fo:simple-page-master> 
     </fo:layout-master-set> 
     <fo:page-sequence master-reference="simpleA4"> 
     <fo:flow flow-name="xsl-region-body"> 
      <fo:block font-size="14pt"> 
      <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="3pt">  
      <fo:table-column column-width="50%"/> 
      <fo:table-column column-width="50%"/> 
      <fo:table-body> 
       <xsl:apply-templates select="item"/> 
      </fo:table-body> 
      </fo:table> 
      </fo:block> 
     </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
    </xsl:template> 
    <xsl:template match="item"> 
    <fo:table-cell text-align="center"> 
     <xsl:if test="position() mod 2 = 1"> 
     <xsl:attribute name="starts-row">true</xsl:attribute> 
     </xsl:if> 
     <fo:block> 
     <fo:external-graphic height="scale-to-fit" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"> 
      <xsl:attribute name="src">url('<xsl:value-of select="image"/>')</xsl:attribute> 
     </fo:external-graphic> 
     </fo:block> 
     <fo:block> 
     <fo:external-graphic height="scale-to-fit" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"> 
      <xsl:attribute name="src">url('<xsl:value-of select="barcode"/>')</xsl:attribute> 
     </fo:external-graphic> 
     </fo:block> 
     <fo:block wrap-option="wrap"> 
     <xsl:value-of select="name"/> 
     </fo:block> 
    </fo:table-cell> 
    </xsl:template> 
</xsl:stylesheet> 

這個偉大的工程,因爲它填補了一個表有兩列與我的數據。

這將填滿表格「水平」,就像左邊的表格一樣。

我重新評估我的要求,並意識到,我想它來填充「垂直」像右表:

---------------  ----------------- 
| 1 | 2 | | 1 | (n/2)+1 | 
| 3 | 4 | | 2 | (n/2)+2 | 
| ... | ... | | ... | ... | 
| n-1 | n | | n/2 | n | 
---------------  ----------------- 

理想情況下,我想移動到下一列在頁面的末尾,在下一頁的第一欄中重新開始,但我認爲這是不可能的。

這是我的XML的例子:

<barcode-list> 
    <item> 
     <name>the-barcode</name> 
     <barcode>file:///d:/pdf/barcode.png</barcode> 
     <image>file:///d:/test.png</image> 
     <format>CODE_128</format> 
    </item> 
    ... 
</barcode-list> 

我發現this,似乎提出一個解決方案留言板項,但我不能換我的頭周圍它做什麼。

任何人都可以給我任何指示如何開始?

+0

創建一個兩列的文件,而不是一個表 –

+0

@KevinBrown是否允許我自動進入頁面末尾的下一列,或者它會在第一頁的第二列開始之前基本填滿所有頁面的第一列? – Baz

+1

兩列文檔將填充左列,然後是右列,下一頁再次填充等等。 –

回答

4

使用雙列文檔佈局,您的內容塊(帶有兩個圖像和一個標籤)將沿頁面向下流動,然後流向下一列。這將在後續頁面上繼續。以下是一個示例FO和結果。有幾件事情需要注意:

  • 兩列是通過將列數的區域體
  • 每一個與你的重複內容的容器是保together.within-塊容器內實現列設置爲「始終」,以確保您的兩個圖像和一個標籤都在一起,而不是跨列或頁面分割。
  • 我確實改變了你的圖形規範的規模以適應的是不正確的寬度/高度

樣品FO代碼(注意,我只在這裏表示第一幾個街區,我數點,以顯示訂單):

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
<fo:layout-master-set> 
    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> 
     <fo:region-body column-count="2"/> 
    </fo:simple-page-master> 
</fo:layout-master-set> 
<fo:page-sequence master-reference="simpleA4"> 
    <fo:flow flow-name="xsl-region-body"> 
     <fo:block-container font-size="14pt" text-align="center" keep-together.within-column="always"> 
      <fo:block> 
       <fo:external-graphic src="url('box.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>     
      </fo:block> 
      <fo:block> 
       <fo:external-graphic src="url('brick.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/> 
      </fo:block> 
      <fo:block wrap-option="wrap"> 
       Object Name 1 
      </fo:block> 
     </fo:block-container> 

     <fo:block-container font-size="14pt" text-align="center" keep-together.within-column="always"> 
      <fo:block> 
       <fo:external-graphic src="url('box.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>     
      </fo:block> 
      <fo:block> 
       <fo:external-graphic src="url('brick.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/> 
      </fo:block> 
      <fo:block wrap-option="wrap"> 
       Object Name 2 
      </fo:block> 
     </fo:block-container> 

樣本輸出爲9塊:

enter image description here

+0

輝煌,正是我期待的。謝謝! – Baz