views:

484

answers:

3

I have an XML document here that is served with a corresponding XSL file. The transformation is left to be executed client-side, without JavaScript.

This works fine in IE (shock horror), but in Google Chrome, just displays the document's text nodes.

I know that it is possible to do client-side XSL in Chrome, as I have seen examples of it, but I am yet to be able to replicate this success myself

What am I doing wrong?

+1  A: 

FYI - it doesn't work in FireFox either as-is. I was able to get it to work in FireFox by making either of the following changes:

  1. Omit the XML declaration <xsl:output indent="yes" method="xml" media-type="text/xhtml" omit-xml-declaration="yes" />

  2. Change your output method to "html" (which will omit the XML declaration): <xsl:output indent="yes" method="html" media-type="text/xhtml" />

  3. BOTH CHANGES <xsl:output indent="yes" method="html" media-type="text/xhtml" omit-xml-declaration="yes" />

I'm also having trouble getting it to work in Chrome. I even tried adding the XHTML namespace to the output without success.

It looks like there may not be support for stylesheet processing instructions on XML files in Chrome at the moment...

Mads Hansen
According to w3c, there [is support](http://www.w3schools.com/xsl/xsl_browsers.asp).
Eric
[Here](http://tecfa.unige.ch/guides/xml/examples/xsl-simple/animals.xml)'s a working example in chrome. Now why does that work, but mine not?
Eric
The problem is Chrome, it doesn't read XSL files correctly on the wire, there are some bugs filed for that, but there are workarounds as I explained below.
Mohamed Mansour
+4  A: 

Ooh, solved it!

You've gotta have an XHTML namespace declaration:

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

Now why is that not mentioned anywhere on the internet?

Eric
Good find! Filled a bug for this.
Mohamed Mansour
Do I get an upvote for said 'good find'?
Eric
+! for answering your own question
Mads Hansen
One more and I get a badge!
Eric
@Eric: +1 for answering your own question :PEnjoy your e-badge of e-approval.
Will Morgan
A: 

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

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

Alejandro
See [my answer](http://stackoverflow.com/questions/2981524/how-can-i-make-xslt-work-in-chrome/2981917#2981917), I've solved it. Chrome seems to require an `xmlns` attribute.
Eric
I don't think so. To perform the transformation, Chrome does not need to set the default namespace to XHTML namespace. To render XHTML it needs proper XHTML, of course. You are mixing things.
Alejandro