Fallback strategy for rendering locally downloaded

2019-08-24 03:28发布

问题:

Internally in our collaboration we exchange XML files with state information about our experiment. The source of these XML files is a central website where we would like the files to be rendered with a XSL stylesheet. When a collaborator downloads the XML file to her local computer and tries to open the file in Firefox (or anything else than Safari it seems) the browser refuses to load the now external XSL file due to cross-domain conflict. This behaviour is survivable, the problem is that many browsers instead of showing the raw XML which would be helpful shows an error:

Error loading stylesheet: An unknown error has occurred
(805303f4) http://user.web.cern.ch/user/grl_xslt/grl.xsl

Is there a way to tell the browser that in case the XSL file is unavailable, show the raw XML or apply another CSS based stylesheet?

回答1:

You could consider to configure your server to allow the access, for instance when I load a local file with the contents

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://home.arcor.de/martin.honnen/cdtest/test2012050101.xsl"?>
<root>
  <foo>
    <bar>test</bar>
  </foo>
</root>

with Firefox 12 it applies the remote stylesheet as the server for that directory is configured to allow cross origin access with the HTTP header Access-Control-Allow-Origin "*". https://developer.mozilla.org/en/HTTP_access_control

Note however that I get different results with Opera, it displays the document tree stating that no associated stylesheet was found.

And Chrome refuses the access to the external stylesheet as unsafe.