如果表格内容使用xslt扩展到PDF格式的下一页,则表格页脚不会出现

时间:2018-05-09 11:34:09

标签: xslt xsl-fo

如果表格延伸到下一页,则表格页脚未显示。

继续文字应位于第一页中该表的末尾。类似于正确到来的表头。每当表格扩展到下一页时," cont"应该出现在第一页的末尾。

  

示例XML:

<NewDataSet>
    <DefaultView>
     <Department>2222</Department>
     <Title>Manish</Title>
   </DefaultView>
   <DefaultView>
     <Department>2223</Department>
     <Title>Santosh</Title>
   </DefaultView>
   <DefaultView>
     <Department>2224</Department>
     <Title>Naveen</Title>
   </DefaultView>
   <DefaultView>
     <Department>2225</Department>
     <Title>punith</Title>
   </DefaultView>
   <DefaultView>
     <Department>2226</Department>
     <Title>bharath</Title>
   </DefaultView>
   <DefaultView>
     <Department>2227</Department>
     <Title>vijay</Title>
   </DefaultView>
 </NewDataSet>
  

示例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">
        <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>
          <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>
              <xsl:for-each select="*">
                <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>
              </xsl:for-each>
            </fo:table>
          </fo:table-and-caption>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>

示例输出: enter image description here

1 个答案:

答案 0 :(得分:1)

将此与关于表格标题(Table header is not getting repeated, if table content extended to next page in PDF using XSLT)的其他答案相结合,这是一个完整的示例,显示表格标题和页脚在表格结束时作为标记拉入页脚区域。

    <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:region-after extent="1in"/>
                    </fo:simple-page-master>
                </fo:layout-master-set>
                <fo:page-sequence master-reference="my-page">
                    <fo:static-content flow-name="xsl-region-after">
                       <!-- This retrieves the marker into the footer -->
                        <fo:block>
                           <fo:retrieve-marker retrieve-class-name="table" retrieve-position="last-ending-within-page"/>
                        </fo:block>
                    </fo:static-content>
                    <fo:flow flow-name="xsl-region-body">
                       <!-- This sets the marker content for the footer -->
                        <fo:block>
                            <fo:marker marker-class-name="table">
                                Table continued on next page
                            </fo:marker>
                        </fo:block>
                            <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>
                        <!-- IMPORTANT -- This clears the marker so it does not appear on pages where the table ends -->
                        <fo:block keep-with-previous.within-page="always">
                            <fo:marker marker-class-name="table"/>
                        </fo:block>
                    </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>

结果是:

enter image description here

如果你有很多页面是:

enter image description here

如果您的页面少于一页:

enter image description here