Saxon9HE 错误 XLM0001:嵌套的应用模板调用过多.样式表可能会循环 [英] Saxon9HE error XLM0001: Too many nested apply-templates calls. The stylesheet may be looping

查看:27
本文介绍了Saxon9HE 错误 XLM0001:嵌套的应用模板调用过多.样式表可能会循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Saxon9HE 来转换一些 XML 2.0.来自 Java 类;解决方案来自这个较早的问题
我正在将双管道分隔文本转换为 XML.
但是,某些字段包含人们的简历,并且转换会引发标题中提到的循环错误.

I'm using Saxon9HE to transform some XML 2.0. from a Java class; the solution is from this earlier question
I'm transforming double pipe delimited text into XML.
However, some of the fields contain people's resumes and the transform throws the looping error mentioned in the title.

有没有办法解决这个问题?我读到了增加模板堆栈中的最大深度,但这仅适用于 Oxygen;Saxon9HE.jar 中是否有类似的设置?

Is there a way fix this? I read about increasing the maximum depth in templates stack but that only applies to Oxygen; is there a similar setting in the Saxon9HE.jar?

这是代码,您也可以点击上面的链接获取代码

Here's the code, you can also click on the link above to get the code

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="str">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:analyze-string select="." regex="\|((\|\s*[^|]+\s*\|)+)\|">
      <xsl:matching-substring>
        <xsl:analyze-string select="regex-group(1)" regex="\|\s*(\w+):([^|]+?)\s*\|">
          <xsl:matching-substring>
            <xsl:element name="{regex-group(1)}">
              <xsl:value-of select="regex-group(2)"/>
            </xsl:element>
          </xsl:matching-substring>
        </xsl:analyze-string>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:value-of select="."/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:copy>
</xsl:template>


</xsl:stylesheet>  

谢谢,

推荐答案

有两种可能:要么样式表在做无限递归,要么在做最终会终止的深度递归,但需要太多的堆栈空间.

There are two possibilities: either the stylesheet is doing infinite recursion, or it is doing deep recursion that would terminate eventually, but requires too much stack space.

>

第一步是找出哪些适用,我们无法在没有看到您的代码的情况下做到这一点.

The first step is to find out which of these applies, and we can't do that without seeing your code.

如果它是非终止递归,那么显然这是您的代码中需要修复的错误.

If it's non-terminating recursion then obviously that's a bug in your code that needs to be fixed.

如果是深度但有限的递归,那么可能会通过增加可用资源来解决,但这取决于您与极限的接近程度.作为一个实用的经验法则,不要尝试深度超过 500 级的递归.

If it's deep but finite recursion, then there may be a solution by increasing the resources available, but it depends how close to the limit you are. As a practical rule-of-thumb, don't attempt a recursion that goes more than about 500 levels deep.

有多种方法可以重写代码以避免深度递归:

There are a number of ways of rewriting the code to avoid deep recursion:

(a) 您或许可以利用 Saxon 的尾调用优化

(a) you may be able to take advantage of Saxon's tail-call optimization

(b) 你可以使用分而治之的递归算法来代替头尾递归

(b) you may be able to use a divide-and-conquer recursive algorithm in place of head-tail recursion

(c) 您可以完全避免递归,例如通过使用 xsl:iterate 或 xsl:analyze-string 或 fold-left() 函数.

(c) you may be able to avoid recursion altogether, for example by using xsl:iterate or xsl:analyze-string or the fold-left() function.

但是如果不了解您正在尝试做什么,我们将无法提供更多帮助.给我们看代码!

But we can't help much further without seeing what you are trying to do. Show us the code!

这篇关于Saxon9HE 错误 XLM0001:嵌套的应用模板调用过多.样式表可能会循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆