XSL堆栈溢出问题

当XSLT模版递归处理大量数据时,可能导致解析器堆栈溢出。本文介绍了一种通过数据切割的方法来避免此问题,即先将数据分割成小批次处理,减少单次递归所需的数据量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当模版递归次数达到一定数量时,会将XSLT解析器(这里指是MSXML4.0)的堆栈空间占用完,造成溢出,因为每次递归都会有临时变量产生。解决方法:将数据量切割,这里我们采用recordset保存为xml格式,然后通过XSL文件进行匹配,生成HTML格式流,假设DB中有2万条数据,每页显示10条,要2000页,此时可能会溢出,如果我们再添加一个递归,将2万条/1000页,表示如果每次递归显示1000页需要的递归次数(这里应该是2)。这样如果有1000万数据,两个递归都递归1000次,如果大于1000万,可以再增加一个递归模版。
<xsl:template match="w:tc"> <fo:table-cell border="1pt solid black" padding="2pt" display-align="center"> <xsl:variable name="totalCols" select="count(ancestor::w:tbl/w:tblGrid/w:gridCol)"/> <xsl:variable name="precedingSpanSum"> <xsl:choose> <xsl:when test="preceding-sibling::w:tc"> <xsl:value-of select="sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) + count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:if test="w:tcPr/w:gridSpan"> <xsl:variable name="declaredSpan" select="w:tcPr/w:gridSpan/@w:val"/> <xsl:variable name="remainingCols" select="$totalCols - $precedingSpanSum"/> <xsl:attribute name="number-columns-spanned"> <xsl:choose> <xsl:when test="$declaredSpan > $remainingCols"> <xsl:value-of select="$remainingCols"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$declaredSpan"/> </xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:if> <!-- 修正的行合并逻辑 --> <xsl:if test="w:tcPr/w:vMerge[@w:val='restart']"> <xsl:variable name="currentPos" select="count(preceding-sibling::w:tc) + 1"/> <xsl:variable name="rowSpan"> <xsl:call-template name="calculateRowSpan"> <xsl:with-param name="remainingRows" select="../following-sibling::w:tr"/> <xsl:with-param name="position" select="$currentPos"/> <xsl:with-param name="count" select="1"/> </xsl:call-template> </xsl:variable> <xsl:attribute name="number-rows-spanned"> <xsl:value-of select="$rowSpan"/> </xsl:attribute> </xsl:if> <fo:block linefeed-treatment="ignore" white-space-collapse="true"> <xsl:apply-templates select=".//w:p"/> </fo:block> </fo:table-cell> </xsl:template> <!-- 新增递归模板 --> <xsl:template name="calculateRowSpan"> <xsl:param name="remainingRows"/> <xsl:param name="position"/> <xsl:param name="count"/> <xsl:choose> <xsl:when test="not($remainingRows) or $position > count($remainingRows[1]/w:tc)"> <xsl:value-of select="$count"/> </xsl:when> <xsl:otherwise> <xsl:variable name="nextCell" select="$remainingRows[1]/w:tc[$position]"/> <xsl:choose> <xsl:when test="$nextCell/w:tcPr/w:vMerge[@w:val='continue']"> <xsl:call-template name="calculateRowSpan"> <xsl:with-param name="remainingRows" select="$remainingRows[position() > 1]"/> <xsl:with-param name="position" select="$position"/> <xsl:with-param name="count" select="$count + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$count"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template>上述xslt样式表中表格的列合并单元格正常,但是行合并失效,我应该怎么修改?一定要注意这是word的xml转xls-fo的xlst样式表,且xslxml版本均为1.0,请直接给出修改结果
最新发布
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值