Google-chrome – Chrome, Firefox and Safari not applying XSLT? IE does!

firefoxgoogle-chromesafarixslt

The below is returned to the browser:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="to_xhtml.xslt"?>
    <root>
      <value>test data</value>
    </root>

Chrome 7 and FF 5 do not appy the XSLT only showing the XML values. IE does apply the XSLT showing the resultant XHTML.

The XSLT file is there and is valid – I can proccess the XML locally and open the resulting XHTML in Chrome and Firefox…

The web server is IIS 6 and interface is PHP 5.3 if that has anything to with it?

UPDATE: XSLT:

<?xml version='1.0'?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">

  <xsl:output 
    method='xml' 
    indent='yes'
    doctype-public='"-//W3C//DTD XHTML Basic 1.1//EN"
    "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"'/>

  <xsl:template match="/root">
    <html>
      <head>
        <title>
        </title>
      </head>
      <body>
        <p>
            <xsl:value-of select="value"/>
        </p>
    ...
  </html>

Best Answer

You need to ensure your page is served with the correct HTTP Content-Type header value in this case: text/xml, possible in PHP using the header function:

header('Content-type: text/xml');
echo $xmlStr;

*thanks to meder who lead me in the right direction for this.

Also In Chrome and Safari an error still occurs while applying the XSLT because of the above doctype-public value:

<xsl:output 
method='xml' 
indent='yes'
doctype-public='"-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"'/>;

It should be:

<xsl:output 
  method="xml"
  indent="yes"
  doctype-public="-//W3C//DTD XHTML Basic 1.1//EN"
  doctype-system="http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"/>

The doctype-public attribute should not even be looked at if doctype-system is not specfied according to the spec.

*thanks to LarsH for pointing out doctype-system should be in a separate value.

Related Topic