troubleshooting Question

XslCompiledTransform instead of XslTransform??

Avatar of animated405
animated405 asked on
ASP.NET
2 Comments1 Solution1235 ViewsLast Modified:

I'm trying to convert a 1.1 c# project and am having issue using the XslCompiledTransform to tranform a recordset into a html file like I was able to do with XslTranform.

In this code, the dataset is written into a file, but it is not using the xslt to format the document properly. It simply prints out the results:

System.IO.StringWriter sw = new System.IO.StringWriter();
            XmlDocument xmlDoc = new XmlDocument();
            XslCompiledTransform xslTran = new XslCompiledTransform();
            System.Xml.XmlTextWriter writer;
            XmlElement root;
            XPathNavigator nav;

//write the xml to a string
            ds.WriteXml(sw);
//write string to XmlDocument
            xmlDoc.LoadXml(sw.ToString());
            sw.Close();

//contrary to some code examples in csharp-corner I got an xslt compile error (need to include the dtd processing and pass into the XmlReader.Create method) when NOT including the XmlReaderSettings
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ProhibitDtd = false;
            settings.ValidationType = ValidationType.None;
//Load the stylesheet
            xslTran.Load(XmlReader.Create(templateFile, settings));
            root = xmlDoc.DocumentElement;
            nav = root.CreateNavigator();
//instantiate the write we will pass the transform into
            writer = new XmlTextWriter(file, Encoding.Default);
//transform while navigating through the xml
            xslTran.Transform(nav, null, writer);

            writer.Close();
            writer = null;
            xmlDoc = null;

I receive no build erros on this. Still learning some of the basics and having trouble understanding why this doesn't work. Thanks in advance!!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros