我可以使用 CORS 查看远程服务器上引用 XSLT 的 XML 文件吗?
Can I use CORS to view an XML file that references an XSLT on a remote server?
我知道 Same-Origin policy issues of serving content that references content on another server. However, I found CORS (Cross-Origin Resource Sharing) 并希望它能做我想做的事。我还没有任何运气,主要是因为我不完全理解它。我也很难找到 CORS 和 XML/XSLT.
的示例
这是我所做的:
1.将以下内容添加到我的 web.config
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
2。创建了以下名为 hello.xml
的 XML 文件并将其上传到 scott.host/
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://scott.host/hello.xsl"?>
<hello-world> <greeter>An XSLT Programmer</greeter> <greeting>Hello, World!</greeting></hello-world>
3。创建了以下名为 hello.xsl
的 XSL 文件并将其上传到另一个域(同一服务器)
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/hello-world">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<H1>
<xsl:value-of select="greeting"/>
</H1>
<xsl:apply-templates select="greeter"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
当我访问 http://scott.host/hello.xml
时,它正确显示,并按预期进行了转换。但是,当我访问 http://otherdomain/hello.xml
时,出现 Request for cross-domain XSLT was denied
错误。
我是不是做错了什么?
注意:发布后我在我的网络配置中禁用了 Access-Control-Allow-Origin
条目。
参考文献:
据我测试,支持取决于浏览器,Mozilla 浏览器支持它,因为 http://home.versanet.de/~martin-honnen/xslt/test2015070201.xml the stylesheet from http://home.arcor.de/martin.honnen/cdtest/test2015070201.xsl 被 Firefox 应用,而 IE(用 IE 11 测试)说
Die Anforderung für domänenübergreifendes XSLT wurde verweigert."
("The request for a cross-domain XSLT was refused")
和Chrome也给出类似的错误
Unsafe attempt to load URL
http://home.arcor.de/martin.honnen/cdtest/test2015070201.xsl from
frame with URL
http://home.versanet.de/~martin-honnen/xslt/test2015070201.xml.
Domains, protocols and ports must match.
我知道 Same-Origin policy issues of serving content that references content on another server. However, I found CORS (Cross-Origin Resource Sharing) 并希望它能做我想做的事。我还没有任何运气,主要是因为我不完全理解它。我也很难找到 CORS 和 XML/XSLT.
的示例这是我所做的:
1.将以下内容添加到我的 web.config
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
2。创建了以下名为 hello.xml
的 XML 文件并将其上传到 scott.host/
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://scott.host/hello.xsl"?>
<hello-world> <greeter>An XSLT Programmer</greeter> <greeting>Hello, World!</greeting></hello-world>
3。创建了以下名为 hello.xsl
的 XSL 文件并将其上传到另一个域(同一服务器)
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/hello-world">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<H1>
<xsl:value-of select="greeting"/>
</H1>
<xsl:apply-templates select="greeter"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
当我访问 http://scott.host/hello.xml
时,它正确显示,并按预期进行了转换。但是,当我访问 http://otherdomain/hello.xml
时,出现 Request for cross-domain XSLT was denied
错误。
我是不是做错了什么?
注意:发布后我在我的网络配置中禁用了 Access-Control-Allow-Origin
条目。
参考文献:
据我测试,支持取决于浏览器,Mozilla 浏览器支持它,因为 http://home.versanet.de/~martin-honnen/xslt/test2015070201.xml the stylesheet from http://home.arcor.de/martin.honnen/cdtest/test2015070201.xsl 被 Firefox 应用,而 IE(用 IE 11 测试)说
Die Anforderung für domänenübergreifendes XSLT wurde verweigert." ("The request for a cross-domain XSLT was refused")
和Chrome也给出类似的错误
Unsafe attempt to load URL http://home.arcor.de/martin.honnen/cdtest/test2015070201.xsl from frame with URL http://home.versanet.de/~martin-honnen/xslt/test2015070201.xml. Domains, protocols and ports must match.