我找到了很多答案,如何生成正在运行的标题和表格标题,但没有人符合条件:
我找到retrieve-table-marker
,并在每一行上放置标记,但有了它,我只能在两个条件下使用:
1-2(最后一个表格片段也有"继续表格#34;标题)
<retrieve-table-marker retrieve-position-within-table="first-starting"/>
2-3(第一个片段有&#34;继续表&#34;)
<retrieve-table-marker retrieve-position-within-table="last-ending"/>
所以,如果我发现如何做下一件事,它就可以解决了:
如果可能,我可以设置类似
的内容<fo:table-row>
<xsl:choose>
<xsl:when test="is-last-fragment()">
<fo:marker marker-class-name="table-header">End of table</fo:marker>
</xsl:when>
<xsl:when test="position() = 1">
<fo:marker marker-class-name="table-header">End of table</fo:marker>
</xsl:when>
<xsl:otherwise>
<fo:marker marker-class-name="table-header">Continue of table</fo:marker>
</xsl:when>
</xsl:choose>
</fo:table-row>
并在表格标题中使用<retrieve-table-marker retrieve-position-within-table="first-starting"/>
。
retrieve-table-marker
标记上的其他标记隐藏第一个/最后一个标记。我使用Saxonica的saxonb-xslt-9.1.0.8J作为xslt处理器并使用fop-2.1生成pdf。
UPD: XML数据:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<numbers>
<number>1</number>
<number>2</number>
<number>2</number>
<number>2</number>
<number>2</number>
<number>2</number>
<number>2</number>
<number>2</number>
<number>11</number>
<number>2</number>
<!-- and so on. Just dummy lines -->
</numbers>
XSL样式:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.1">
<xsl:strip-space elements="*"/>
<xsl:template match="numbers">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<fo:region-body region-name="body" margin="2cm"/>
<fo:region-before margin="4cm" extent="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="body">
<fo:table>
<fo:table-column/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block border-bottom-style="solid" border-bottom-color="black">
<fo:retrieve-table-marker retrieve-class-name="cont"
retrieve-position-within-table="last-ending"
retrieve-boundary-within-table="table-fragment"/> 
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="number">
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>
<xsl:if test="position() != 1 and position() != last()">continued</xsl:if>
<xsl:if test="position() = last()">ended</xsl:if>
</fo:inline>
</fo:marker>
<fo:block>
value: <xsl:apply-templates/> on line <xsl:value-of select="position()" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
这产生了XSL-FO:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<fo:region-body region-name="body" margin="2cm"/>
<fo:region-before margin="4cm" extent="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="body">
<fo:table>
<fo:table-column/>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block border-bottom-style="solid" border-bottom-color="black">
<fo:retrieve-table-marker retrieve-class-name="cont" retrieve-position-within-table="last-ending" retrieve-boundary-within-table="table-fragment"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline/>
</fo:marker>
<fo:block>
value: 1 on line 1</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 2</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 3</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 4</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 5</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 6</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 7</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 8</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 11 on line 9</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 2 on line 10</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>continued</fo:inline>
</fo:marker>
<fo:block>
value: 11 on line 11</fo:block>
</fo:table-cell>
</fo:table-row>
<!-- and so on... -->
<fo:table-row>
<fo:table-cell>
<fo:marker marker-class-name="cont">
<fo:inline>ended</fo:inline>
</fo:marker>
<fo:block>
value: 12 on line 172</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>