XSLT不是在Web浏览器中工作 [英] XSLT not working in web browser

查看:137
本文介绍了XSLT不是在Web浏览器中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML风格XSLT文件。该XSLT是通过URL访问:没有问题( HTTP //someurl/somefile.xsl

I have an XSLT file for styles in XML. The XSLT is accessible via a URL (http://someurl/somefile.xsl) without problems.

当我插入相同的URL到 xml样式表处理指令,它只是呈现在浏览器(FF,IE)纯文本,

When I insert the same URL into an xml-stylesheet processing instruction, it only renders plain text in browsers (FF, IE),

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://someurl/somefile.xsl"?>
<rootElement>...</rootElement>

但是当我使用本地文件路径(文件下载到同一文件夹中的XML文件),它就像一个魅力:

but when I use a local file path (file downloaded to same folder as the XML file), it works like a charm:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="somefile.xsl"?>
<rootElement>...</rootElement>

为什么?

推荐答案

在浏览器中运行XSLT是受到一些限制:

Running XSLT in a Web Browser

Running XSLT in the browser is subject to some limitations:


  • XSLT 2.0没有被任何主流Web浏览器的支持。

  • XSLT 2.0 is not supported by any of the major web browsers.

浏览器的安全模式就有所不同XSLT处理。

Browser security models differ regarding XSLT processing.


  • 跨域限制往往需要从同一产地的该XML的XSLT负荷。 (这似乎咬你在这种情况下)。

  • Cross-domain restrictions will often require that the XSLT load from the same origin as the the XML. (This appears to be biting you in this case.)

Chrome并不允许本地加载XSLT运行(即使是在本地加载XML)。这可能是在开发过程中恼人的。

Chrome does not allow locally loaded XSLT to run (even when the XML is locally loaded). This can be annoying during development.

有关这些原因,XSLT更常在服务器上或在批处理模式,而不是在浏览器中运行。

For these reasons, XSLT is more often run on the server or in batch mode rather than in the browser.

如果您想在浏览器中运行XSLT和有它的Chrome,火狐和IE的工作,你必须


  1. 使用XSLT 1.0只,的的XSLT 2.0。

  2. 使用的 xml样式表 XML文件中的处理指令,你对我所做的XSLT文件与XML文件链接:

  1. Use XSLT 1.0 only, not XSLT 2.0.
  2. Use an xml-stylesheet processing instruction in the XML file as you've done to link the XSLT file with the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://origin-domain/path/to/file.xsl"?>
<rootElement>...</rootElement>


  • 从服务器即成XSLT,而不是从本地文件。

  • 确保该XSLT来自同一个域作为XML起源。

  • 最后,一定要检查浏览器控制台任何错误消息。例如,这里就是IE显示了当XSLT不能位于:

    Finally, be sure to check the browser console for any error messages. For example, here's what IE shows when the XSLT cannot be located:

    这篇关于XSLT不是在Web浏览器中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆