在xslt中最好(更快)的替代方法是什么?
1/带有模板
<xsl:template name="str-replace">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="str-replace">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>2/具有扩展对象
public class ToolBox
{
public string replace(string s, string el, string by)
{return s.Replace(el, by);}
}
<xsl:value-of select="toolbox:replace($foo,$bar, $fobar)" />发布于 2011-06-17 11:47:14
性能问题取决于您所使用的产品。本机代码几乎肯定会更快,但在某些处理器上,调用扩展函数的开销很高。所以量一下吧。
或者切换到XSLT2.0。
发布于 2011-06-17 10:26:28
为了直接回答您的问题,我期望字符串操作方法优于XML操作,因为它不需要解析XML文档。
但是,您应该考虑是否希望替换文档对文档的XML性质敏感。也就是说,你是否只是想:
<hello>替换为<there>的字符串将改变启动的<hello>元素,而不是关闭的</there>元素。G 29
https://stackoverflow.com/questions/6384223
复制相似问题