【问题标题】:Why is the Replace function is not working in xslt 2.0为什么替换功能在 xslt 2.0 中不起作用
【发布时间】:2014-08-11 10:08:19
【问题描述】:

替换功能在 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>

当我们使用替换功能时,我们会得到这个错误:

我正在检查在线 xslt 测试仪上的 replace 功能,有些工具出现错误,有些不是为什么?

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 中处理这个 replace 函数

提前致谢

【问题讨论】:

  • 这是试图合并双重转义的 & 符号吗?在这种情况下,您需要再次转义 &amp;amp;replace($ShortDescription, '&amp;amp;amp;amp;', '&amp;amp;amp;')
  • 我检查了双重转义的&符号,但它不起作用。我的问题是为什么用 firefox 和 chrome 替换在我的 xslt 2.0 中不起作用的功能。
  • 我怀疑原因是您没有使用 XSLT 2.0 处理器。我不知道您如何为 solr 4.0 配置 XSLT 2.0 处理器的选择,但仅将 version="2.0" 放在样式表中可能还不够。
  • 感谢您的回复。我应该做些什么来定义 xslt 2.0 版并使用替换功能?

标签: xml xslt-2.0


【解决方案1】:

www.utilities-online.info/xsltransformation/#.U-inrWNknIU ==> 给出错误

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

http://www.xsltcake.com/ ==> 给定错误

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

http://xslt.online-toolz.com/tools/xslt-transformation.php ==> 给定错误

该工具使用 XSLT 1.0 (libxsl)

http://xslttest.appspot.com/ ==> 没有给出错误。它工作正常。

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

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog ==> 给定错误

该工具使用 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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 2015-07-16
    相关资源
    最近更新 更多