【发布时间】:2016-07-19 22:25:45
【问题描述】:
我尝试使用 XSLT 1.0 版将 XML 文件转换为 Json 格式,我正在使用 XSL 上的 Replace 方法进行潜在的替换。这会产生 StackOverFlowException。
Replace 方法是递归调用的,所以我遇到了这个问题。有什么解决方案可以解决这个问题吗?
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
【问题讨论】:
-
您使用哪种 XSLT 1.0 处理器?
-
我没有使用任何 XSLT 1.0 特殊处理器,我是使用 XSLT 的新手
-
通过您的处理器运行home.arcor.de/martin.honnen/xslt/processorTest2.xml 并告诉我们结果。或者继续使用 Saxon 9、Altova 或 XmlPrime 提供的 XSLT 2.0。
-
您能否提供一个发生此行为的示例 XML?以及最初调用模板的方式(以确定您传递给参数的内容)。
标签: xml xslt xml-parsing xslt-1.0