這是我前一段時間發佈的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,似乎提出一個解決方案留言板項,但我不能換我的頭周圍它做什麼。
任何人都可以給我任何指示如何開始?
創建一個兩列的文件,而不是一個表 –
@KevinBrown是否允許我自動進入頁面末尾的下一列,或者它會在第一頁的第二列開始之前基本填滿所有頁面的第一列? – Baz
兩列文檔將填充左列,然後是右列,下一頁再次填充等等。 –