8

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 and displays them in a browser, transformed with stylesheets that are hosted on a remote server.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
TJF
  • 2,248
  • 4
  • 28
  • 43

2 Answers2

7

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).

therealmarv
  • 3,692
  • 4
  • 24
  • 42
  • @Tom maybe switch to a javascript solution like e.g. jquery transform. This should work without rewriting the XSLT (but did not tested it) [Example here](http://stackoverflow.com/questions/2042178/chrome-and-safari-xslt-using-javascript/2042441#2042441) – therealmarv Jul 09 '11 at 01:48
  • My xml and xslt have a root element and a template, I just left that out as I just wanted to show the header, should have included everything. Your answer confirms though that this is due to security restrictions (web and local) - so there is no way to make it work with without changing the xml and the way it's transformed? – TJF Jul 11 '11 at 14:30
  • 1
    There are several (bad) solutions but I think that the best is you change the way your program transforms this XML, do not rely on browser XSLT, use your own XSLT library if you want to show reports. Here are some bad solutions: - Downgrade your IE to IE8. - Try it with firefox. - Try running Chrome with this [Chromium Bug Comment](http://code.google.com/p/chromium/issues/detail?id=70088#c12) – therealmarv Jul 11 '11 at 16:25
  • ok thanks, I just tested applying the XSLT within the application when it receives that XML and that seems to be working fine – TJF Jul 11 '11 at 16:52
3

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.

Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137