When the document(uri) function is used to load another document within the XSLT, where the target document contains a DTD I get an XslTransformException, containing an inner XmlException:
For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method.
As the XmlReader is created within the XSLT implementation there is no direct way to create the XmlReader with the settings I want, and none of the XslCompiledTransform, XmlResolver1 or related classes seem to provide any form of hook.
(I’m using a DTD to set some HTML entities to make the authoring of the document easier.)
1 based on looking at XmlUrlResolver in Reflector this just loaded the URI’s target as a Stream.
E.g. is the XSLT contains
<xsl:apply-templates select="document('more.xml')/root"/>
and more.xml contains a DTD then the exception above is the result.
The same
XmlResolveryou pass to theTransformmethod is used for document function, this resolver can return anXmlReaderthat allows DTD, instead of returningStream. You can also returnIXPathNavigable. In other words, you need a specialized implementation ofXmlResolverto fix this issue.