Fallback strategy for rendering locally downloaded XML files with external XSL stylesheets

左心房为你撑大大i 提交于 2019-12-25 02:33:35

问题


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.



来源:https://stackoverflow.com/questions/10411647/fallback-strategy-for-rendering-locally-downloaded-xml-files-with-external-xsl-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!