使用XSL样式表从XML生成PDF时显示页码(其HTML输出)

时间:2018-05-08 09:26:36

标签: html xml xslt xslt-1.0

我试图从XML文件生成PDF,并且我有一个数据表,其中包含表中近100行。每个PDF页面只显示40行。  因此,PDF在表格中为100行生成3页。此外,在每个页面上还显示页眉和页脚。

现在,我试图在每个页面的顶部显示页码。我不确定如何显示页码

我有相同的地方持有人

 <!-- variable ReportHeader-->
<xsl:variable name="ReportHeader">
    <table class="tableReportHeader" cellspacing="0">
        <tr>
            <td>
                <img class="imglogo" src="image_header.png" />
            </td>
            <td>
                <h3 style="color:darkblue; font-family: Arial;">INVOICE</h3>
                <h3 style="color:darkblue; font-family: Arial;">Page : </h3>
            </td>
        </tr>
    </table>
</xsl:variable>

例如:

 Page No : 1/3
 Page No : 2/3
 Page No : 3/3

请找到我的完整XSL样式表

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="urn:extra-functions">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="Data">
            <html>
                <head>
                    <title>Invoice</title>
            </head>


                <body>
                    <xsl:copy-of select="$ReportHeader"/>

                    <xsl:call-template name="Filler">
                        <xsl:with-param name="fillercount" select="1" />
                    </xsl:call-template>


                    <xsl:copy-of select="$OrderHeader"/>


                    <xsl:copy-of select="$OrderRowsHeader"/>

                    <xsl:for-each select="Order/OrderRows/OrderRow">

                        <table class="tabledetails" cellspacing="0" style="table-layout:fixed">
                            <tr>
                                <td class="tdmargin" />
                                <td style="width:70px" align="right" class="blueline">
                                    <xsl:value-of select="ProductID" />
                                    <xsl:value-of select="translate(' ', ' ', '&#160;')"/>
                                </td>

                                <td class="tdmargin" />
                            </tr>
                        </table>
                        <xsl:if test="(position() mod 40) = 0 ">
                            <!--40 rows per page-->
                            <xsl:call-template name="Filler">
                                <xsl:with-param name="fillercount" select="1" />
                            </xsl:call-template>

                            <xsl:copy-of select="$ReportFooter" />

                            <br class="pagebreak" /> <br />

                            <xsl:copy-of select="$ReportHeader" />



                            <xsl:copy-of select="$OrderRecipient"/>

                            <xsl:call-template name="Filler">
                                <xsl:with-param name="fillercount" select="1" />
                            </xsl:call-template>

                            <xsl:copy-of select="$OrderHeader"/>



                            <xsl:copy-of select="$OrderRowsHeader"/>

                        </xsl:if>
                    </xsl:for-each>

                    <xsl:copy-of select="$ReportFooter"/>

                </body>
            </html>


        </xsl:template>


    <!-- variable ReportHeader-->
    <xsl:variable name="ReportHeader">
        <table class="tableReportHeader" cellspacing="0">
            <tr>
                <td>
                    <img class="imglogo" src="image_header.png" />
                </td>
                <td>
                    <h3 style="color:darkblue; font-family: Arial;">INVOICE</h3>
                    <h3 style="color:darkblue; font-family: Arial;">Page : </h3>
                </td>
            </tr>
        </table>
    </xsl:variable>
    <!-- variable OrderHeader-->
    <xsl:variable name="OrderHeader">
        <table class="tabledetails" cellspacing="0" >
            <tr>
                <td class="tdmargin" />
                <th>
                    Order ID:
                </th>

                <td class="tdmargin" />
            </tr>
            <tr>
                <td class="tdmargin" />
                <td class="tdorderHeader">
                    <xsl:value-of select="/Data/Order/OrderID" />
                    <xsl:value-of select="translate(' ', ' ', '&#160;')"/>
                </td>

                <td class="tdmargin" />
            </tr>
        </table>
    </xsl:variable>

    <!-- variable ReportFooter-->
    <xsl:variable name="ReportFooter">
        <table class="tableReportFooter">
            <tr>
                <td style="width:20px;"></td>
                <td>
                    <table>
                        <tr>
                            <td style="font-size: 5pt; text-align: justify;border-top: solid DarkBlue 1px;">
                                One Portals Way, Twin Points WA  98156 Phone: 1-206-555-1417   Fax: 1-206-555-5938
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width:20px;"></td>
            </tr>
        </table>
    </xsl:variable>

    <!--variable OrderRowsHeader-->
    <xsl:variable name="OrderRowsHeader">
        <table class="tabledetails" cellspacing="0" style="table-layout:fixed">
            <tr>
                <td class="tdmargin" />
                <th style="width:70px">
                    Product ID:
                </th>

            </tr>
        </table>
    </xsl:variable>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

在您的for-each内,您可以计算页码,与分页符非常相似。

 <xsl:value-of select="ceiling(position() div  40)"/>

这将当前循环位置与每页的项目数分开。结果四舍五入到下一个整数值。通过这种方式,您可以从迭代1到40获得1,从迭代41获得2到......你得到它。

但是,要在ReportHeader中使用此值,您必须使ReportHeader成为命名模板,并将值作为参数传递给它。基本上与Filler相同。

相关问题