xml - 如何在 Internet Explorer 中将 xslt 文件中的 document-uri 显示为 html 文档中的文本?

标签 xml internet-explorer xslt internet-explorer-9 xslt-2.0

我有以下两个文件。当我尝试在 Internet Explorer 9 中查看 xml 文档时,它不使用 xslt 文件进行翻译。

我的 xml 文件

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="xsl.xslt"?>
<foo>
  <bar>baz</bar>
</foo>

我的 xslt 文件

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
>
    <xsl:output method="html"/>
  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="/foo/bar"/>
        </title>
      </head>
      <body>

        <!-- It works if i remove the following xsl:value-of tag -->

        <xsl:value-of select="document-uri()"/>
        <div style="color: #ff0000;">
          <xsl:value-of select="/foo/bar/text()"/>
        </div>
        <div style="color: #ff0000;">RED</div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

当我删除<xsl:value-of select="document-uri()"/>时标记 xml 已正确翻译。 我尝试过以下 document-uri 的用法:

  • 文档-uri()
  • 文档-uri('/')
  • 文档-uri('/foo')
  • 文档-uri('foo')
  • fn:文档-uri()
  • fn:文档-uri('/')
  • fn:document-uri('/foo')
  • fn:ocument-uri('foo')

最佳答案

document-uri() 是一个 XPath 2.0 函数,而不是 XPath 1.0 函数。

Internat Explorer 在内部使用 MSXML,它是仅 XSLT 1.0 的处理器,不支持 XPath 2.0。

因此,你运气不好。

仅供引用 - 目前 5 个主要浏览器均未实现 XSLT 2.0。

如果您想在浏览器中使用 XSLT 2.0,可以使用 Saxon CE 来实现。

最近 Michael Kay 宣布 Saxon CE 的下一版本将完全开源 - 现已推出

关于xml - 如何在 Internet Explorer 中将 xslt 文件中的 document-uri 显示为 html 文档中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14994190/

相关文章:

css - 为什么在 IE 上滚动时固定的背景图像会移动?

xml - 使用 xsl 选择填充变量

rest - REST MarkLogic 中的自定义搜索结果

javascript - 为什么我得到一个 {"location": null} when I try to convert a text/xml into an object?

javascript - 如何将 XSL 属性值传递到 HTML5 数据标记中?

internet-explorer - 为什么 ie 在遇到 <fb :xxx> fbml elements when correctly using the fbml xmlns? 时显然会回流 DOM

javascript - 使用javascript扫描目录

c# - XSLT 格式代码文档 (xml) 中的换行符

java - 如何在 JAXB 中解码 xml 时处理特殊字符

xml - xsd 中的可为空 bool 字段