tags:

views:

262

answers:

1

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

and more.xml contains a DTD then the exception above is the result.

+2  A: 

The same XmlResolver you pass to the Transform method is used for document function, this resolver can return an XmlReader that allows DTD, instead of returning Stream. You can also return IXPathNavigable. In other words, you need a specialized implementation of XmlResolver to fix this issue.

Max Toro
Thanks, this works. Time for some feedback on the documentation which completely fails to mention you can return something other than Stream.
Richard
@Richard: http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx is the best documentation on XslCompiledTransform.
Max Toro
They changed the URL, here's the new one: http://blogs.msdn.com/b/xmlteam/archive/2005/11/16/introducing-xslcompiledtransform.aspx
Max Toro