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!!
ASP.NET

Avatar of undefined
Last Comment
animated405

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Vivek Thangaswamy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23