Fix for IE’s lack of application/xhtml+xml by Mit The Destroyer
Have you ever tried sending a 100% strictly compliant xhtml to IE, so that IE would use It’s xml engine to render the page? If so, you know that IE borks on it and forces you to download the xhtml file. I’m here to tell you that I’ve found a work around, that is standards compliant and gets around that limitation and forces IE to use the XML rendering engine. Two steps are required for it to work:
- Configure web server to send xhtml files with the mime type of application/xml
- Then attach a XSL sheet to each xhtml file you serve to IE
Example xhtml code
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="fixMe.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<title>Simple Example < /title>
</head>
<body>
<!-- xhtml code here -->
<body>
</html>
Required fixMe.xsl code
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="/">
<xsl:copy-of select="node()"/>
</xsl:template>
</xsl:stylesheet>
Why does this work?
As far as IE is concerned you sent it a XML file, with an XSLT sheet applied to it. It’s XML rendering engine then applies the XSLT sheet which converts the XML page into an XHTML page. Without the XSLT sheet applied IE would have just showed us the source code to the page.
How did you ever figure this out?
I discovered this when I was developing this website, to teach myself XSLT. And knowing what I know about mime-types I figured it should work if I just changed the mime-type for XHTML from application/xhtml+xml to it’s alternate compliant mime-type of application/xml1, seeing as IE wasn’t having any issues displaying XML files sent as application/xml.
Additional Notes
Update: To see an example with SVG and MathML mixed in with the XHTML read So now that IE unerstands pure XHTML…
