开发者

IE9 and Chrome not rendering XML with XSL if XML is local and XSL is on remote server

开发者 https://www.devze.com 2023-03-18 02:50 出处:网络
I have the following XML: <?xml version=\"1.0\"?> <?xml-stylesheet type=\"text/xsl\" href=\"http://www.test.com/AuditTrail.xsl\"?>

I have the following XML:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.test.com/AuditTrail.xsl"?>

and XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <html>
        <head><title>Test</title></head>
    </html>
</xsl:stylesheet>

This works fine in IE8 but not in IE9 or Chrome. I have read that IE9 seems to prohibit loading XSL from a remote server if the XML source file is on the local machine. Is there any way to get IE9 and Chrome to apply a remote XSL file to a local XML file without messing with the security settings of the browsers? We have a desktop application that generates XML reports an开发者_运维百科d displays them in a browser, transformed with stylesheets that are hosted on a remote server.


Does this work locally? I do not think so because there are some errors in both XML and XSLT.

Chrome blocks local XML and XSLT processing! It is a issue or they disabled it for security reasons. Look at this Chrome Bug Report for some work-arounds.

IE9 disabled the support of mixture of local XML and remote XSLT. Also for security reasons! (I do not have a link for that)

Your XML needs to have at least one root element:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.test.com/AuditTrail.xsl"?>
<hello/>

and your XSLT needs to have some XSLT templates:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <html>
    <head><title>Test</title></head>
    </html>
</xsl:template>

</xsl:stylesheet>

With this corrections this example will work for IE8 and Firefox.
In Chrome the XML and XSLT needs to be on a webserver. In IE9 both need to be on a webserver or locally stored (without mixture).


We have a desktop application that generates XML reports and displays them in a browser, transformed with stylesheets that are hosted on a remote server

I think that simplest way is to download or store/cache (last copy of) stylesheet via HTTP protocol on user's local hard disk (using that application) and then perform "fully-legal" client-side transformation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号