gpt4 book ai didi

XSL-FO 连续表头

转载 作者:行者123 更新时间:2023-12-02 11:50:45 25 4
gpt4 key购买 nike

我正在使用 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"/>
&#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>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 行:如您所见,第一行有一个标记“TOOLING:-”,所有其他行都有一个标记“TOOLING:(续)”,这就是我想要的。

我的问题是我似乎无法使 fo:retrieve-table-marker 对象正常工作:我尝试了与“retrieve-position”和“retrieve-boundary”属性的多种组合,但每次我的标题第一行始终为空白,无论是在第一页还是在其他页面上。

如果有人可以向我解释我对这些“fo:retrieve-table-marker”和“fo:marker”对象做错了什么,那将是一个真正的帮助,我一直在努力解决这个问题已经几天了。

最佳答案

您已设置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>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>

关于XSL-FO 连续表头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com