XSL变量或参数'CurrentPageCount'未定义

时间:2018-05-08 13:36:03

标签: xslt compiler-errors xslt-1.0

生成PDF时尝试在页面开头显示页码。例如Page 1 / 3 Page 2 / 3 Page 3 / 3

请找到我想要显示的以下代码行。

`<td >Seite/Page  <xsl:value-of select="$CurrentPageCount" />  / <xsl:value-of select="count(delivery_receipt/order_items) div 5"/> 
                    </td>`

CurrentPageCount变量值,从下面得到代码<xsl:variable name="CurrentPageCount" select="position()" />

但它不适合我给出以下错误

`line 156: Variable or parameter 'CurrentPageCount' is undefined.'`

请在下面找到我的整个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:variable name="CurrentPageCount" select="position()" />
                    <xsl:copy-of select="$ReportHeader"/>
                    <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="blueline" style="width:220px" >
                                    <xsl:value-of select="ProductName" />
                                    <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:if>
                    </xsl:for-each>



                    <!--Filler -->
                    <xsl:choose>
                        <!-- case of only one page-->
                        <xsl:when test="count(Order/OrderRows/OrderRow) &lt;= 40">
                            <xsl:call-template name="Filler">
                                <xsl:with-param name="fillercount" select="40 - (count(Order/OrderRows/OrderRow))"/>
                            </xsl:call-template>
                        </xsl:when>
                        <!-- case of more than one page-->
                        <xsl:otherwise>
                            <xsl:call-template name="Filler">
                                <!--(Rows per page = 40) -  (Rows in current page) - (Total section rows = 1 ) + (Filler Row = 1)-->
                                <xsl:with-param name="fillercount" select="40 - ( ( count(Order/OrderRows/OrderRow)-40 ) mod 40 ) - 3 + 1"/>
                            </xsl:call-template>
                        </xsl:otherwise>
                    </xsl:choose>
                    <!--End Filler -->

                    <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 >INVOICE</h3>
                </td>
                    <td >Seite/Page  <xsl:value-of select="$CurrentPageCount" />  / <xsl:value-of select="count(delivery_receipt/order_items) div 5"/> 
                    </td>

            </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>

    <!-- Template Filler-->
    <xsl:template name="Filler">
        <xsl:param name="fillercount" select="1"/>
        <xsl:if test="$fillercount > 0">
            <table class="tabledetails">
                <tr>
                    <td>
                        <xsl:value-of select="translate(' ', ' ', '&#160;')"/>
                    </td>
                </tr>
            </table>
            <xsl:call-template name="Filler">
                <xsl:with-param name="fillercount" select="$fillercount - 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <!--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>
                <th style="width:220px">
                    Product Name:
                </th>

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

</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

首先,fo支持使用

进行页面计数
<fo:pagenumber/> 

以及引用最后一页的总页数。见:How to show page number (N of N) using xslt in PDF Report。 所以你应该使用它。如果您仍然坚持按照自己的方式进行操作,则可以在模板中添加参数,如:

<xsl:template name="ReportHeader">
    <xsl:param name="currentPage"/>
    <table class="tableReportHeader" cellspacing="0">
        <tr>
            <td>
                <img class="imglogo" src="image_header.png" />
            </td>
            <td>
                <h3>INVOICE</h3>
            </td>
            <td >
                <xsl:text>Seite/Page: </xsl:text>
                <xsl:value-of select="$currentPage" /> 
                <xsl:text>/</xsl:text>
                <xsl:value-of select="count(delivery_receipt/order_items) div 5"/> 
            </td>
        </tr>
    </table>
</xsl:template>

并调用模板而不是变量,如:

<xsl:call-template name="ReportHeader">
    <xsl:with-param name="currentPage" select="$CurrentPageCount"/>
</xsl:call-template>
相关问题