GSerg
GSerg

Reputation: 78183

XSL -> XHTML with doctype set in the template, won't transform

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.


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?

Upvotes: 2

Views: 3170

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

I think the problem with MSXML 6 is that by default it neither allows DTDs nor it loads them (or any external resources in general). So to avoid the validation message you need to set both (I am using JScript syntax, please adjust to your language of choice):

xmlTransformedResult.resolveExternals = true;
xmlTraansformedResult.setProperty('ProhibitDTD', false);

Then I think you won't get the validation error. At least as long as the W3C is going to serve up the XHTML DTD files, I think when you do that programmatically a lot you might get errors but that does not depend on MSXML, that is simply a W3C policy to avoid too much traffic on their servers by everyone fetching such DTDs.

Upvotes: 1

Related Questions