[ACCEPTED]-How to enable XSLT scripting in C# ..?-xslt
As Steve cooper has mentioned .. you need to enable the XSLT 3 script .. and here is the way to do it:
first define a new
var settings = new XsltSettings();
then 2 enable the script
settings.EnableScript = true;
XslCompiledTransform object and 1 load the style sheet, passing in the
In the MSDN Documentation it says "XSLT scripting is 10 disabled by default. XSLT scripting should 9 be enabled only if you require script support 8 and you are working in a fully trusted environment."
This 7 is probably your problem. Try loading the 6 transform like this;
XslCompiledTransform xslt = new XslCompiledTransform(); // Disable script blocks and the document() function // if a stylesheet came from an untrusted source string untrustedUri = @"http://www.untrusted-site.com/meow.xsl"; XmlResolver secureResolver = new XmlSecureResolver(new XmlUrlResolver(), untrustedUri); xslt.Load(untrustedUri, XsltSettings.Default, secureResolver); // Enable script blocks and the document() function // if a trusted stylesheet needs them xslt.Load(@"C:\MyProject\purr.xsl", XsltSettings.TrustedXslt, new XmlUrlResolver());
You could add some detail 5 to your question, too; can you say how you 4 are able to do it manually? What program 3 or engine are you using? For instance, XMLSpy 2 uses a different transform engine from the 1 .Net framework, so XSL files can be incompatable.
Define the settings variable Enabling Script 2 Mode and then use it in the load process.
var settings = new XsltSettings(); settings.EnableScript = true; XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("input.xsl", settings , null);
It 1 worked for me. Regards!
I would suggest trying to load the XML file 7 completely separately - I wouldn't be surprised 6 to find that this had nothing at all to 5 do with XSL, and everything to do with it 4 not being able to find the file or something 3 similar.
Try loading the XML file into an 2
XmlDocument and checking that it looks correct. If 1 that works, use the overload accepting an
IXPathNavigable as input (
More Related questions