问题
Table header is not added to next page, if table content is extended to next page. Header is getting displayed for multiple tables, but if table content extends to next page then header is not coming and its staring the table row in next page. Need to append header before starting next page, if table content extends. Sample XML:
<NewDataSet>
<DefaultView>
<Department>2222</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2222</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2222</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2222</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2223</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2223</Department>
<Title>vijay</Title>
</DefaultView>
<DefaultView>
<Department>2223</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2223</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>vijay</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2224</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2225</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2225</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2225</Department>
<Title>vijay</Title>
</DefaultView>
<DefaultView>
<Department>2225</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2225</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2226</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2226</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2226</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2226</Department>
<Title>vijay</Title>
</DefaultView> <DefaultView>
<Department>2226</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2226</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>vijay</Title>
</DefaultView> <DefaultView>
<Department>2227</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>vijay</Title>
</DefaultView> <DefaultView>
<Department>2227</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>vijay</Title>
</DefaultView> <DefaultView>
<Department>2227</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>vijay</Title>
</DefaultView> <DefaultView>
<Department>2227</Department>
<Title>Manish</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Santosh</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>Naveen</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>punith</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>bharath</Title>
</DefaultView>
<DefaultView>
<Department>2227</Department>
<Title>vijay</Title>
</DefaultView>
</NewDataSet>
Sample XSL:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:rx="http://www.renderx.com/XSL/Extensions"
xmlns:psmi="http://www.CraneSoftwrights.com/resources/psmi"
xmlns:exsl="http://exslt.org/common">
<xsl:template match='NewDataSet'>
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<xsl:for-each select="*">
<xsl:variable name="tempdept">
<xsl:value-of select="Department" />
</xsl:variable>
<xsl:variable name="dept">
<xsl:value-of select="preceding-sibling::DefaultView[1]/Department" />
</xsl:variable>
<xsl:if test="$dept != $tempdept" >
<xsl:call-template name="header"/>
</xsl:if>
<fo:table-and-caption>
<fo:table rx:table-omit-initial-header="true">
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-header keep-together="always">
<fo:block text-align="center" font-style="italic" margin="5pt" keep-together="always">
<xsl:text>Table (Cont.)</xsl:text>
</fo:block>
</fo:table-header>
<fo:table-header >
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block font-weight="bold">Dept</fo:block>
</fo:table-cell >
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block font-weight="bold">Title</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block>
<xsl:value-of select="Department"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block>
<xsl:value-of select="Title"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-and-caption>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name='header'>
<fo:table>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-header keep-together="always">
<fo:block text-align="center" font-style="italic" margin="5pt" keep-together="always">
<xsl:text>Table</xsl:text>
</fo:block>
</fo:table-header>
<fo:table-header >
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block font-weight="bold">Dept</fo:block>
</fo:table-cell >
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" align="left">
<fo:block font-weight="bold">Title</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
</fo:table>
</xsl:template>
</xsl:stylesheet>
Sample O/P Screenshot: 1. With multiple table: Table header with multiple table 2. Header is not coming if table content extends to next page: Header is not coming if table content extends to next page
回答1:
Just a total guess as you had many issues, but perhaps this is what you were trying to do. This XSL creates "rows" for each DefaultView and only one table with a repeating header with no table (cont) at the start only at the break.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:rx="http://www.renderx.com/XSL/Extensions"
xmlns:psmi="http://www.CraneSoftwrights.com/resources/psmi"
xmlns:exsl="http://exslt.org/common">
<xsl:template match='NewDataSet'>
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:table-and-caption>
<fo:table rx:table-omit-initial-header="true">
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-header keep-together="always">
<fo:table-row>
<fo:table-cell number-columns-spanned="2"><fo:block text-align="center" font-style="italic" margin="5pt" keep-together="always">
<xsl:text>Table (Cont.)</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block font-weight="bold">Department</fo:block>
</fo:table-cell >
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block font-weight="bold">Title</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block font-weight="bold">Depaartment</fo:block>
</fo:table-cell >
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block font-weight="bold">Title</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:table-and-caption>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="DefaultView">
<fo:table-row>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block>
<xsl:value-of select="Department"/>
</fo:block>
</fo:table-cell>
<fo:table-cell border-color="black" border-style="solid" width = "85pt" border-width="0.4pt" padding="3pt" >
<fo:block>
<xsl:value-of select="Title"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
The result is (in two page view):
来源:https://stackoverflow.com/questions/50255529/table-header-is-not-getting-repeated-if-table-content-extended-to-next-page-in