xml - 为什么替换功能在 xslt 2.0 中不起作用

标签 xml xslt-2.0

替换功能在 xslt 2.0 中不起作用

xslt 看起来像这样:

 <xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:fn='http://www.w3.org/2005/xpath-funcations'>

    <xsl:output
           method="xml"
           encoding="utf-8"
           media-type="application/xml"
      />
      <xsl:template match='/'>

        <items>
             <xsl:apply-templates select="response/result/doc"/>
        </items>

      </xsl:template>

      <!-- search results xslt -->
      <xsl:template match="doc">

    <xsl:variable name="ShortDescription" select="str[@name = 'ShortDescription']"/>

    <shortdescription><xsl:value-of select="replace($ShortDescription, '&amp;amp;', '&amp;')" disable-output-escaping="yes"/></shortdescription>

    </xsl:template>

    </xsl:stylesheet>

当我们使用替换函数时,我们收到此错误:

enter image description here

我正在检查在线 xslt 测试仪上的替换功能,有些工具给出了错误,有些则不是,为什么会这样?

www.utilities-online.info/xsltransformation/#.U-inrWNknIU   ==> given error
http://www.xsltcake.com/                                    ==> given error
http://xslt.online-toolz.com/tools/xslt-transformation.php  ==> given error
http://xslttest.appspot.com/                                ==> not given error.its working fine.
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog ==> given error

我正在使用 solr 4.0,xslt 2.0 和 xml 1.0

请告诉我如何在 xslt 2.0 中处理此替换功能

提前致谢

最佳答案

www.utilities-online.info/xsltransformation/#.U-inrWNknIU ==> given error

该工具使用 XSLT 1.0 (javax.xml.transform)

http://www.xsltcake.com/ ==> given error

该工具使用 XSLT 1.0(浏览器版本,即 Firefox 中的 Transformiix)

http://xslt.online-toolz.com/tools/xslt-transformation.php ==> given error

该工具使用 XSLT 1.0 (libxsl)

http://xslttest.appspot.com/ ==> not given error.its working fine.

该工具使用 XSLT 2.0(来自 Saxonica 的 SAXON 9.3.0.5)

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog ==> given error

该工具使用 XSLT 1.0(浏览器版本,即 Firefox 中的 Transformiix)

正如其他人已经评论的那样,函数 fn:replace是 XSLT 2.0(实际上是 XPath 2.0,它是 XSLT 2.0 的一部分)中添加的功能。使用 2.0 处理器运行样式表(如 SaxonExseltAltova ),应该没问题。如何为您的产品配置它取决于它是否支持使用/插入不同的处理器。

注意:您使用的命名空间 fn是错的。您不需要指定该命名空间(它是隐式的),但如果您这样做,请使用 xmlns:fn="http://www.w3.org/2005/xpath-functions" .

关于xml - 为什么替换功能在 xslt 2.0 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25240756/

相关文章:

xml - 从两个 xml 文件在 XSLT 中排序

java - 解码时出现意外元素

css - 如何在 Oxygen 中使用 XSLT 从单个 XML 文件拆分为 3 个 JSON

java - 使用 apache commons 配置 xpath 查询具有属性的空 XML 元素

xslt - 计算忽略空白节点的节点

c# - 将 XDocument 优化为 XDocument XSLT

javascript - 在 Javascript 中解析 XML 到 JSON 转换的对象

python - 在 XML 中保存元组列表

xml - 列出元素 XSLT 的子节点

xslt - xslt中多次出现相同的路径