tags:

views:

33

answers:

1

As I understand it, you need to include the following code at the top of your HTML files to make sure they're parsed properly:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
...

I'm generating an html file by transforming an XML file using an XSL file. This is going to be done using the MSXML tool, which produces a standard HTML file as output.

If I just do this:

<xsl:template match="/">
<html>
...

Everything is fine. But if I do this:

<xsl:template match="/">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
...

I get the error XML Parsing Error: XML or text declaration not at start of entity in Firefox, or Cannot have a DOCTYPE declaration outside of a prolog. in IE. Presumably this is because the parser is finding two <?xml definitions and getting confused.

How do I make the browser a) understand that I am using proper strict HTML, and b) make sure those declarations are put into the HTML output file that MSXML generates?

+3  A: 

The doctype can be controlled using the xsl:output element.

Pete Kirkham
I think that works when I'm viewing the XML through XSL in a browser, but not when I run the MSXML "Generate HTML from these XML and XSL files" tool. :(
Colen
@Colen: no, xsl:output is part of the standard. It should "just work".
John Saunders
If it doesn't, then use a conforming XSLT processor.
Pete Kirkham
Everything that I've found says that the MSXML stuff is "conforming", so I don't understand why this isn't working.
Colen
Just because Microsoft says that they're conforming, doesn't mean that they actually are. After all, they've been claiming that Internet Explorer was standards compliant forever...
Craig Trader