Link to home
Start Free TrialLog in
Avatar of animated405
animated405

asked on

XslCompiledTransform instead of XslTransform??


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
Avatar of Vivek Thangaswamy
Vivek Thangaswamy
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of animated405
animated405

ASKER

the problem wasn't actually that I was using the XmlCompileTransform improperly, but instead the node name difference with the table that was getting returned vs. what I was looking for in my xslt.

Points because I was using your code to test when I finally ran into the error that told me so, thanks!