问题
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.
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>
Thank you,
回答1:
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.
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) you may be able to take advantage of Saxon's tail-call optimization
(b) you may be able to use a divide-and-conquer recursive algorithm in place of head-tail recursion
(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!
来源:https://stackoverflow.com/questions/18018332/saxon9he-error-xlm0001-too-many-nested-apply-templates-calls-the-stylesheet-ma