Wednesday, February 13, 2008

Firefox loading an XSLT file - MIME type required

Posted this as a question on comp.text.xml: http://groups.google.com/group/comp.text.xml/browse_frm/thread/b3e34e9bc37c0057/80bd928ac0e6c94f#80bd928ac0e6c94f.

I am doing some XSLT work with my Javascript loading the XML to be converted and the XSLT stylesheet to do the converting using the following method.

function loadXMLDoc(fileName) {
  var xmlDoc;
  xmlDoc = document.implementation.createDocument("", "", null);
  xmlDoc.async = false;
  xmlDoc.load(fileName);
  return(xmlDoc);
} 
loadXMLDoc("stylesheet.xslt"); // XSLT Stylesheet
loadXMLDoc("data.xml");        // XML data to be rendered in HTML via XSLT

This worked in IE, but wasn't working in Firefox (2.0.0.12). The problem turned out to be MIME types in Firefox. My server wasn't set up to have a MIME type ("application/xml" or "text/xml") for my XSLT file and Firefox was failing because of this! Worse, it didn't output any sort of error message to let me know.

My workaround was to re-name the XSLT file to have an XML extension.

No comments: