I'm trying to produce a valid XHTML document from XML data.
I'm doing so using MSXML object library, not .NET. With .NET there are no problems, transforms just fine.
My XSL template has this:
<xsl:output
method="xml"
omit-xml-declaration="no"
indent="no"
version="1.0"
encoding="utf-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>
Then goes:
<xsl:template match="/root">
<html xmlns="http://www.w3.org/1999/xhtml">
...
</html>
</xsl:template>
And there come problems.
If I use MSXML2.DOMDocument40, MSXML refuses to generate the XHTML because
The attribute '{xmlns}' on this element is not defined in the DTD/Schema.
Apparenty, one of the HTML tags in the template body is not allowed to have the namespace it inherits from
<html>
. But MSXML won't tell me which tag that is.If I just strip out everything from the template and dump the XML data enclosed in
<p>
, then it transforms fine. Apparently,<p>
is allowed to havexmlns
.What tag is that, which ruins everything for me?
If I use MSXML2.DOMDocument60, I first have to say:
xmlTransformedResult.setProperty("ProhibitDTD", False)
, otherwise I get "DTD is prohibited."
Having that setting set, I get:
The element 'html' is used but not declared in the DTD/Schema.
How can I fix that?
If I use .NET transformation, it's all fine. The generated document starts with
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
Now, I can remove both doctype-public
and doctype-system
from the template, produce just plain XML, and then manually prepend the header to it. But I don't wan't to. What is the proper way of making this work?