【发布时间】: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;', '&')" 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;:replace($ShortDescription, '&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 版并使用替换功能?