Setting the DOCTYPE in XSL

Album Cover: Flight of the Conchords

"She's so hot, she's making me sexist."
Flight of the Conchords / Boom

Posted on November 16, 2006 10:03 PM in XML
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

Earlier today, I wrote a bit about how to get :hover to work in IE7. The solution involved making sure the appropriate DOCTYPE was set.

Well, what happens if you're working with XML and want to use an XSLT, but still want to be sure the output will keep you out of IE7's quirks mode?

At first glance, you might think you don't have any control over the DOCTYPE, since your transformation will likely barf if you try to include a DOCTYPE explicitly. Fortunately, the XSLT spec provides several output methods for you to choose from. In dealing with HTML and XHTML, you'll most likely be interested in the HTML output method and XML output method, respectively.

XML to XHTML Transformations with XSLT Processors gives a really nice rundown on how you can specify your desired DOCTYPE from within your XSLT. For instance, if you wanted to use the HTML 4.01 Strict DOCTYPE that was one of the options for keeping IE7 out of quirks mode, you'd include the following in your XSLT:

<xsl:output method="html" doctype-system="" doctype-public="-//W3C//DTD HTML 4.01//EN" indent="yes" />

So there you have it, an easy way to make sure your XSLT output conforms to the DOCTYPE of your choosing.


Joe on June 08, 2007 at 11:13 AM:

You just saved me hours of work. Thanks.


Haroon Latif on December 17, 2007 at 8:45 AM:

very helpful. Thanks


sip on April 24, 2008 at 2:12 AM:

Thanks, that's exaclty what I was looking for.


suphi basdemir on November 28, 2008 at 8:40 AM:

thanks a lot for this information!


WebDev on March 16, 2010 at 2:17 AM:

Thank you very much! It helped a lot!


Vicente on March 29, 2011 at 11:31 PM:

Infinite thanks, you're the man.

Muchas gracias!


Frank on April 14, 2012 at 1:43 PM:

exactly what I was looking for. Very helpful, thank you very much.


Oskar on July 10, 2012 at 7:09 AM:

You are a God amongst men, helping me vanquish the evils of IE! THANK YOU!


Robert on July 19, 2012 at 4:55 AM:

I love you.


Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.


Email Address:



Check this box if you hate spam.