Переменная XSL или параметр CurrentPageCount не определены - PullRequest
0 голосов
/ 08 мая 2018

При создании 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 голосов
/ 08 мая 2018

Сначала fo поддерживает наложение страниц с

<fo:pagenumber/> 

и общее количество страниц со ссылкой на последнюю страницу. См. Как показать номер страницы (N из N) с помощью xslt в отчете PDF . Таким образом, вы должны использовать это. Если вы все еще настаиваете на том, чтобы сделать это по-своему, вы можете добавить параметр в свой шаблон, например:

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...