Wednesday, February 13, 2008

Firefox loading an XSLT file - MIME type required

Posted this as a question on comp.text.xml:

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;
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 ( 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: