How can I get XSLT to work in chrome?

I have an XML document here that is served with the corresponding XSL file . The conversion remains executable on the client side, without JavaScript.

This works fine in IE (terrible horror), but Google Chrome just displays the text nodes of the document.

I know that in Chrome you can make an XSL client on the client side, since I saw examples of it, but I still could not reproduce this success myself.

What am I doing wrong?

+71
google-chrome xslt
Jun 05 '10 at 18:25
source share
10 answers

At the time of writing, there was a chrome error, which requires the xmlns attribute to start rendering:

 <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" ... > 

This was a problem that I encountered while working with an XML file from the server.




If, unlike me, you are viewing the xml file from the file:/// URL, then the solutions related to --allow-file-access-from-files you need

+14
Jun 05 '10 at 20:14
source share

The other answer given by Eric is incorrect. The namespace name that he mentioned had nothing to do with this problem.

The real reason it doesn't work is due to security issues (see issue 4197 , issue 111905 ).

Imagine this scenario:

  • You receive an email from an attacker containing a web page as an attachment that you download.

  • You open a local web page in your browser.

  • The local web page creates an <iframe> whose source is https://mail.google.com/mail/ .

  • Since you are logged in to Gmail, the frame uploads messages to your inbox.

  • The local web page reads the contents of the frame using JavaScript to access frames[0].document.documentElement.innerHTML . (An online web page will not be able to complete this step because it will be due to non-Gmail, policies of the same origin will result in reading failure.)

  • The local web page puts the contents of your mailbox in <textarea> and sends the data through the POST form to the attacker's web server. Now the attacker has your mailbox , which can be useful for sending spam or identifying theft.

Chrome captures the script described above places restrictions on local files opened with Chrome. To overcome these limitations, we have two solutions:

  • Try starting Chrome with --allow-file-access-from-files . I have not tested this myself, but if it works, your system will also be vulnerable to this kind of scenario.

  • Upload it to the host and the problem will be resolved.

+101
Jun 06 2018-11-12T00:
source share

I had the same problem on localhost. Running on the Internet looking for an answer, and I claim that adding --allow-file-access-from-files works. I work on a Mac, so I had to go through the terminal sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files and enter my password (if you have one) .

Another little thing - nothing will work if you do not add a link to your .xsl file in your .xml file, as shown below <?xml-stylesheet type="text/xsl" href="<path to file>"?> . Another small thing that I didn’t understand right away is that you have to open your .xml file in a browser, not .xsl.

+4
Dec 15 '12 at 17:38
source share

The Chrome- based issue is not related to the xml namespace , which is xmlns="http://www.w3.org/1999/xhtml" . Without the namesspace attribute, it will not work with IE.

Due to security restrictions, you need to add the --allow-file-access-from-files flag when starting chrome. I think linux / * nix users can easily do this through the terminal, but for Windows users, you should open the properties of the Chrome shortcut and add it to the destination as shown below;

Right click -> Properties -> Target

enter image description here

Here is an example of the full path with flags that I use on my machine;

 "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files 

I hope that showing this step by step will help Windows users for the problem, so I added this post.

+4
Jul 11 '16 at 16:08
source share

Well, this will not work if the XML file (starting with the standard PI:

 <?xml-stylesheet type="text/xsl" href="..."?> 

to refer to the XSL stylesheet) is used as "application / xml". In this case, Chrome will still load the XSL stylesheet that is referenced, but will not display anything, as it silently changes the document types from "application / xml" to "Document" (! ??) and "text / xsl "in" Stylesheet "(! ??), and then tries to display the XML document as if it were an HTML document (5), without starting its first XSLT processor. And nothing will be displayed on the screen (the contents of which will be displayed on the previous page that the XML page refers to, and will continue to rotate the icon, as if the document had never been fully loaded.

You can make good use of the Chrome console, which shows that all resources are loaded, but they are not interpreted correctly.

So, currently only XML files are displayed in Chrome (with its optional XSL style declaration), only if it is used as "text / xml", but not as "application / xml", as necessary for the XML client side with an XSL declaration .

For XML files that have been used as "text / xml" or "application / xml" and that do not contain XSL style declarations, Chrome should still use the default stylesheet to display it as a DOM tree, or at least as her text source. But this is not so, and here he again tries to display it as if it were HTML, and errors immediately on many scripts (including the built-in default) that try to access "document.body" to handle onLoad events and insert some javascript handler in it.

An example of a site that does not work properly (general Lisp documentation) in Chrome, but works in IE, which supports client XSLT:

http://common-lisp.net/project/bknr/static/lmman/toc.html

This index page displays correctly, but all links will access XML documents with a basic XSL declaration in an existing XSL stylesheet document, and you can wait endlessly thinking there are problems in the chapters that need to be downloaded. All you can do to read the documentation is open the console and read the source code in the Resources tab.

+3
May 17 '11 at 12:55
source share

Check out http://www.aranedabienesraices.com.ar

This site is built on the client side of XML / XSLT. It works on IE6-7-8, FF, O, Safari and Chrome. Are you sending HTTP headers correctly? Do you respect policies of the same origin?

+2
Jun 07 '10 at 13:17
source share

As far as I can tell, Chrome is looking for a title

Content-Type: text / xml

Then it works, other iterations failed.

Make sure your web server provides this. He also explains why this fails for files: // URI xml.

+1
May 12 '11 at 23:53
source share

I tried putting the file in wwwroot . Therefore, when accessing a page in Chrome, this is the localhost / yourpage.xml address .

0
Mar 04 '13 at 9:34 on
source share

What Eric says is right.

The following attributes are in xsl for the xsl: stylesheet tag

version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" XMLNS = "http://www.w3.org/1999/xhtml"

It works great in chrome.

0
Dec 07 '14 at 2:14
source share

I started testing this and ran into a local / Chrome file issue. A very simple solution is to put the XML and XSL file in, say, the Dropbox shared folder and get links to both files. Put the link to the XSL transform in the XML head. Use the XML link in Chrome and IT WORKS!

0
Jan 15 '15 at 10:14
source share



All Articles