XSLT替换功能未找到XSLT替换功能未找到(XSLT Replace function not f

2019-05-14 09:37发布

我写这封信中,我想用替换功能做一个正则表达式匹配和替换XSLT转换。

但是,Visual Studio 2008的报告,

“取代()”是一个未知的XSLT函数。

的代码本身的位为:

<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>

有什么,我做错了什么?

谢谢 :)

编辑:我使用这个版本的XSLT,但看起来它是Visual Studio的版本,这是一个问题......我得设法找到一个解决办法。

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

Answer 1:

replace功能仅在XSLT 2.0版可用,而不是1.0版本是什么的Visual Studio使用 。 仅仅因为你已经指定version="2.0"并不意味着Visual Studio中支持它。

下面是实现在XSLT 1.0字符串替换codesling模板 。 您应该能够使用它,但我不能保证其效率。

(从上方连结两者)

<xsl:template name="string-replace-all">
  <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="string-replace-all">
        <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>

你会这样称呼它:

<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>


Answer 2:

取而代之的是不是在XSLT 1.0有效。 你有“翻译()”,这可能会为你工作,但替换()是XSLT 2,而不是MS .NET代码库XML的一部分。 您可以与一些第三方XML库得到它虽然。



Answer 3:

如何嵌入C#脚本来完成更换?

以下内容添加到您的样式表的底部:

<msxsl:script language="C#" implements-prefix="scr"> <![CDATA[ public string Replace(string stringToModify, string pattern, string replacement) { return stringToModify.Replace(pattern, replacement); } ]]> </msxsl:script>

添加一个命名空间属性的样式表元素:

xmlns:scr="urn:scr.this"

然后实现为....

<xsl:value-of select="scr:Replace(description/text(), 'ABC', '123')"/>


Answer 4:

对于简单的字符串替换的翻译功能(在XSLT 1.0可用)为我工作的罚款。

我用它来去掉数字值的空间。



Answer 5:

你应该放在引号之间的功能=串如下

<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


Answer 6:

据我所知, replace()在XLST 2.0引入。 什么是您的文档的版本定义? 也许你已经设定VS 2008使用XLST 2.0(如果可能)。



文章来源: XSLT Replace function not found