Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I get XSLT to work in chrome?

I have a XSLT sample copied straight from http://www.w3schools.com/xsl/xsl_transformation.asp, which I can't seem to view in Google Chrome. However, it seems to work fine in IE.

Does anyone know why this would be?

EDIT:

The online version works fine, but the local copy does not.

like image 603
Eric Avatar asked May 25 '10 13:05

Eric


People also ask

Why XSL is not working in Chrome?

The reason this doesn't work is due to a security concern that Chrome has addressed in a controversial way, by blocking XML files from accessing local XSLT files in the same directory, while HTML files can access . CSS files in the same directory just fine.

How do I run an XSLT file in my browser?

Add the XSLT style sheet using the Properties window. With the XML file open in the editor, right-click anywhere in the editor and choose Properties. In the Properties window, click in the Stylesheet field and choose the browse button (...). Select the XSLT style sheet, and then choose Open.

Which browser supports XSLT?

Web browsers: Safari, Chrome, Firefox, Opera and Internet Explorer all support XSLT 1.0 (only). Browsers can perform on-the-fly transformations of XML files and display the transformation output in the browser window.

Does anyone use XSLT anymore?

XSLT is very widely used. As far as we can judge from metrics like the number of StackOverflow questions, it is in the top 30 programming languages, which probably makes it the top data-model-specific programming language after SQL. But XSLT isn't widely used client-side, that is, in the browser.


2 Answers

I had same issue with Google Chrome (tested on 13.0.782.215) and (non-JavaScript XSL transformation):

<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
  • Online transformation works well e.g. http://www.w3schools.com/xml/simplexsl.xml
  • Local transformation (without server like Apache) show just blank page

I found solution that works for me is to run Chrome browser with --allow-file-access-from-files switch:

// By default, file:// URIs cannot read other file:// URIs. This is an
// override for developers who need the old behavior for testing.
const char kAllowFileAccessFromFiles[]      = "allow-file-access-from-files";
like image 199
Grzegorz Szpetkowski Avatar answered Oct 05 '22 13:10

Grzegorz Szpetkowski


Yeah, if you copied the sample down to a file on your computer, the xml won't work with xslt on chromium because it can't find your xslt file provided by just its filename. I've tried put both the xml file and the xslt file to a web server running on my computer and it worked.

If you don't have a web server on your computer, I have no solution with chromium. But maybe you can try a full path, maybe begun with "file:///C:/". Use other browser if that doesn't work...

Good luck, Max Xie

like image 28
Max Xie Avatar answered Oct 05 '22 15:10

Max Xie