这是我之前发布的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 :(得分:4)
使用两列文档布局,您的内容块(带有两个图像和一个标签)将向下流动页面,然后流向下一列。这将在后续页面上继续。以下是FO和结果示例。有几点需要注意:
示例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个块的样本输出: