Xml 未找到XSLT替换函数
我正在编写一个XSLT转换,其中我希望使用Replace函数进行正则表达式匹配和替换 然而,VisualStudio2008报告说 “replace()”是未知的XSLT函数 代码本身的位是:Xml 未找到XSLT替换函数,xml,regex,xslt,xpath,replace,Xml,Regex,Xslt,Xpath,Replace,我正在编写一个XSLT转换,其中我希望使用Replace函数进行正则表达式匹配和替换 然而,VisualStudio2008报告说 “replace()”是未知的XSLT函数 代码本身的位是: <xsl:otherwise> <td style="border: solid 1px black; background-color:#00CC66;"> <xsl:variable name="FeatureInfo" select="Tex
<xsl:otherwise>
<td style="border: solid 1px black; background-color:#00CC66;">
<xsl:variable name="FeatureInfo" select="Text" />
<xsl:value-of select="replace($FeatureInfo,'Feature=','TESTING')"/>
</td>
</xsl:otherwise>
我做错什么了吗
谢谢:)
Edit:我正在使用此版本的XSLT,但问题似乎出在Visual Studio的版本上……我必须设法找到解决方法
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
替换在XSLT 1.0中无效。您有“translate()”,它可能适合您,但replace()是XSLT 2,而不是MS.NET XML代码库的一部分。但是,您可以通过一些第三方XML库获得它。替换功能仅在XSLT 2.0版中可用,而在1.0版中不可用。仅仅因为您指定了version=“2.0”
,并不意味着Visual Studio支持它
。你应该可以使用它,但我不能保证它的效率
(摘自上面的链接)
你可以这样称呼它:
<xsl:otherwise>
<td style="border: solid 1px black; background-color:#00CC66;">
<xsl:variable name="FeatureInfo" select="Text" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$FeatureInfo"/>
<xsl:with-param name="replace" select="Feature="/>
<xsl:with-param name="by" select="TESTING"/>
</xsl:call-template>
</td>
</xsl:otherwise>
据我所知,replace()
是在XLST 2.0中引入的。文档的版本定义是什么?也许您必须将VS 2008设置为使用XLST 2.0(如果可能)。您应该在引号之间放置Feature=字符串,如下所示
<xsl:otherwise><td style="border: solid 1px black; background-color:#00CC66;"> <xsl:variable name="FeatureInfo" select="Text" /> <xsl:call-template name="string-replace-all"> <xsl:with-param name="text" select="$FeatureInfo"/> <xsl:with-param name="replace" select="'Feature='"/> <xsl:with-param name="by" select="TESTING"/> </xsl:call-template> </td></xsl:otherwise>
Thanks
谢谢
对于简单的字符串替换,translate函数(在xslt 1.0中提供)对我来说运行良好
我用它来去掉数值的空格。嵌入一个c脚本来替换怎么样
将以下内容添加到样式表的底部:
向样式表元素添加名称空间属性:
xmlns:scr=“urn:scr.this”
然后实现为
<xsl:value-of select="scr:Replace(description/text(), 'ABC', '123')"/>
这正是我在寻找的项目。谢谢您需要在s中使用单引号,例如select=“'TESTING”“”。
<xsl:value-of select="scr:Replace(description/text(), 'ABC', '123')"/>