将 XSL 应用于外部 XML [英] Apply XSL to External XML

查看:26
本文介绍了将 XSL 应用于外部 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用:

<?xml-stylesheet type="text/xsl" href="XSL.xsl"?>

将 XSL 链接到 XML.

To link XSL to XML.

如果我的 xml 在这里:www.externaldomain.com/rss.xml(在我的域之外)我怎样才能将 XSL 链接到 XML?

If my xml was here: www.externaldomain.com/rss.xml (Outside of my domain) how can i get the XSL linked to the XML?

我可以将 XSL 指向文件或链接吗?

Can i point the XSL to a File or Link?

推荐答案

你不能用纯"的 xml+xslt(*) 来实现这一点.一些外部代码需要识别应该转换它的 xml 和 xslt.

You can't achieve this with "pure" xml+xslt(*). Some external code will need to identify the xml and the xslt which should transform it.

因为您似乎在转换 XML,所以我猜您是在网络浏览器中执行此操作.

Since you seem to be transforming XML, I'm going to guess you're doing this in the webbrowser.

您可以使用 javascript 执行此操作,如在 w3schools 上演示.但是,如果您正在执行基于 javascript 的请求(即 AJAX/XHR),跨域限制仍然适用:如果原始服务器未设置适当的 CORS 标头以允许跨域 javascript 访问,则您需要代理通过您自己的服务器发送该 xml 请求.

You can do this using javascript, as demonstrated on w3schools. However, cross-domain restrictions still apply if you're doing javascript-based requests (i.e. AJAX/XHR): if the originating server doesn't set the appropriate CORS headers to allow cross-domain javascript access, you'll need to proxy that xml request via your own server.

(*): Mad 的答案 使用实体引用巧妙地将外部 xml 嵌入到包含文档中.绝对值得一试,但请注意,这种基于实体的包含已用于多个信息披露泄漏,这就是为什么在 xml 解析器中通常不启用它(特别是,这不应该能够颠覆浏览器中的 CORS).你只需要在你的情况下尝试一下.

(*): Mad's answer uses entity references to cleverly embed external xml in a containing document. It's definitely worth a try, but be aware that this kind of entity-based inclusion has been used in several information-disclosure leaks, which is why it's often not enabled in the xml parser (in particular, this shouldn't be able to subvert CORS in a browser). You'll just have to try it in your situation.

这篇关于将 XSL 应用于外部 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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