Setting the DOCTYPE in XSL
August 2nd, 2008 by NikhilLast week I created a progessive HTML/CSS layout for a client, tested it in IE6, IE7 and FF 3, seemed perfectly fine… UNTIL! the layout went further down the manufacting cycle. It failed. Page layout elements just went all over the place when the HTML layout was converted into XSL and XML applied to it … Bummer!!!
Could not sleep ok over the weekend, in anticipation of Monday morning, when I’ll have to fix this SH**. But now having a little experince in dealing with these kind of situations ( Browser Quirks, I mean), I knew it had to do with nothing else but DOCTYPE…. and It WAS…
The Problem:
You want control over the DOCTYPE, since your transformation will include a default DOCTYPE explicitly, and you layout will be out for a toss.
The Solution:
XSLT specs provides output methods to set a the DOCTYPE of choise. Also, for us UI developers, the topics of interest would be HTML output methods and XML output methods.
Well! before you get bored , here is the fix.
For eg., if you had the following DOCTYPE in your HTML version :-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Then in the XSL you would have to have the following :-
<xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/loose.dtd" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" indent="yes" />
and Finally! do make sure your XSLT output obeys the DOCTYPEÂ you have chosen.
Tags: Browser Quirks, Doctype, XML, XSL
Subscribe to ExpressingIT by Email | Follow Me on Twitter