I have xslt sheet the have include tags for another xslt files, the all files compiled right and error free but when run the following code i got exception
var myXslTrans = new XslCompiledTransform();
XsltSettings sets = new XsltSettings();
sets.EnableScript = true;
myXslTrans.Load("visio.xsl",sets,null);
myXslTrans.Transform("page1.xml", "page.html");
following the exception text and stacktrace:
System.Xml.Xsl.XslLoadException:
XSLT compile error. An error occurred \bin\Debug\visio.xsl(116,40).
---> System.Xml.XmlException: Resolving of external URIs was prohibited.
at System.Xml.Xsl.Xslt.XsltLoader.Load(XmlReader reader)
at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)
I try to solve the problem by this but the problem still exist
Quotes from comments / updated question:
i copy the files to the project to use it, path variable to get the base directory for the app
Yes, but the path variable is not used, so it has not effect.
System.Xml.Xsl.XslLoadException: XSLT compile error. An error occurred \bin\Debug\visio.xsl(116,40). ---> System.Xml.XmlException: Resolving of external URIs was prohibited.
This may mean one or more of several things:
XslCompiledTransform
, see documentation).xsl:import
, xsl:include
, document()
) or indirectly (via a DTD or to resolve external entities).To resolve, just allow loading of external documents:
Replace this:
XsltSettings sets = new XsltSettings();
sets.EnableScript = true;
with this:
XsltSettings sets = new XsltSettings(true, true);
I noticed another thing. You are setting the last argument to null
, which according to Microsoft should give you a ArgumentNullException
. It is not allowed to be null, but apparently Microsoft now allows it but then it has the effect that the UriResolver
cannot resolve anything, because hey, it is null...
Not quite sure why you set it to null, but try setting it to a valid value, i.e.:
var resolver = new XmlUrlResolver();
myXslTrans.Load("visio.xsl", sets, resolver);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With