我使用XSL-FO生成一些PDF文档,并且有一些表可以跨越多个页面。在这些情况下,我想要做的是在每个新页面的开头重复表格标题,并使用"(续)"除第一页以外的所有页面上的标签。
我的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"/>
 
</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>G3@ITEMSEQ</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTNO</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTDESC</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTQTY</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>G3@ITEMSEQ</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTNO</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTDESC</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTQTY</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>G3@ITEMSEQ</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTNO</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTDESC</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>G3@PARTQTY</fo:block>
</fo:table-cell>
</fo:table-row>
然后继续50行:你可以看到第一个有一个标记&#34; TOOLING: - &#34;所有其他人都有一个标记&#34; TOOLING :(续)&#34;,这就是我想要的。
我的问题是,我似乎无法使fo:retrieve-table-marker对象正常工作:我尝试过多次使用&#34; retrieve-position&#34;和&#34;检索边界&#34;属性,但每次我的标题的第一行总是空白,在第一页或其他页面上。
如果有人能向我解释我对这些&#34; fo:retrieve-table-marker&#34;做错了什么?和&#34; fo:marker&#34;对象,这将是一个真正的帮助,我几天来一直在努力解决这个问题。
答案 0 :(得分: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"/>
 
</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>G3@ITEMSEQ</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTNO</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTDESC</xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text>G3@PARTQTY</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
答案 1 :(得分: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">
...