How do I include the proper XML / HTML definitions in a file generated by XSL?

Posted by Colen on Stack Overflow See other posts from Stack Overflow or by Colen
Published on 2010-06-16T17:02:06Z Indexed on 2010/06/16 17:12 UTC
Read the original article Hit count: 314

Filed under:
|
|

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">
<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">
<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

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?

© Stack Overflow or respective owner

Related posts about html

Related posts about Xml