Setting the DOCTYPE in XSL

Album Cover: The Blueprint

"I've got money stacks bigger than you."
Jay-Z / Takeover

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="http://www.w3.org/TR/html4/strict.dtd" 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.

Comments

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

You just saved me hours of work. Thanks.

Permalink

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

very helpful. Thanks

Permalink

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

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

Permalink

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

thanks a lot for this information!

Permalink

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

Thank you very much! It helped a lot!

Permalink

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

Infinite thanks, you're the man.

Muchas gracias!

Permalink

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

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

Permalink

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

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

Permalink

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

I love you.

Permalink

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.

Name:

Email Address:

Website:

Comments:

Check this box if you hate spam.