html - 从 XML 页数生成 PDF 是错误的
问题描述
我正在从 XML 生成 PDF,一切都按预期进行,唯一的问题是,它额外生成了一页。
我在下面详细解释了这个问题。
页数错误。如果我在一个表中有 20 行并且每页显示 5 行(带有页眉和页脚)。因此,它应该生成 4 个页面,而不是生成 5 个 PDF 页面,最后一页只有页眉和页脚,这是错误的。
请在下面找到我的 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: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(' ', ' ', ' ')"/>
</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>
<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>
<!--Filler -->
<xsl:choose>
<!-- case of only one page-->
<xsl:when test="count(delivery_receipt/order_items) <= 5">
<xsl:call-template name="Filler">
<xsl:with-param name="fillercount" select="5 - (count(delivery_receipt/order_items))"/>
</xsl:call-template>
</xsl:when>
<!-- case of more than one page-->
<xsl:otherwise>
<xsl:call-template name="Filler">
<!--(Rows per page = 5) - (Rows in current page) - (Total section rows = 1 ) + (Filler Row = 1)-->
<xsl:with-param name="fillercount" select="5 - ( ( count(delivery_receipt/order_items)-5 ) mod 5 ) - 3 + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<!--End Filler -->
</body>
</html>
</xsl:template>
<!-- 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(' ', ' ', ' ')"/>
</td>
<td class="tdmargin" />
</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>
<!-- 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(' ', ' ', ' ')"/>
</td>
</tr>
</table>
<xsl:call-template name="Filler">
<xsl:with-param name="fillercount" select="$fillercount - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Template Filler End-->
</xsl:stylesheet>
解决方案
修改了下面的行
<xsl:if test="(position() mod 40) = 0 ">
和
<xsl:if test="(position() mod 40) = 0 and ( position() != last() )">
因此,此问题已得到修复。
推荐阅读
- javascript - 当更改为本地时,onSnapshot fromCache 始终为 false
- javascript - 如何在 React Native 中显示 expo 相机的图像
- excel - Excel 公式在 x 行后停止工作
- javascript - 打字稿中的联合返回类型
- typescript - 使用打字稿处理未定义的返回
- javascript - 如何在分隔的输入字段上禁用 javascript 效果?
- aframe - AR.js,对象实体没有出现在 NFT 标记的顶部并且尺寸非常小
- encryption - 在 GNU 无线电中需要 AES 加密
- mysql - 如何在 mysql/mariadb 中查询具有相同 id 的多行
- java - 同一类的两个对象实例在不同的 JVM 进程中运行