XSLT Transform - C#

XSLT Transform - C#

code snippet

c#
public static string XsltTransform(XmlDocument vobjXmlDocument, string vstrXslPathAbsolute, XsltArgumentList arglist = null)
        {
            // Load Xslt Xml into string 
            TextReader objTextReader = new StreamReader(vstrXslPathAbsolute);
            string strXml = objTextReader.ReadToEnd();
            objTextReader.Close();

            // load the xsl:
            XmlDocument objXmlDocumentStyleSheet = new XmlDocument();
            objXmlDocumentStyleSheet.LoadXml(strXml);

            XslCompiledTransform transform = new XslCompiledTransform(true);
            XsltSettings objXsltSettings = new XsltSettings(true, true);
            XmlUrlResolver objXmlUrlResolver = new XmlUrlResolver();
            transform.Load(objXmlDocumentStyleSheet, objXsltSettings, objXmlUrlResolver);

            // create output streams:
            MemoryStream buffer = new MemoryStream();
            StreamWriter sw = new StreamWriter(buffer);

            // transform the document:
            transform.Transform(vobjXmlDocument, arglist, sw);

            // turn results into a string:
            byte[] chars = buffer.ToArray();
            string output = System.Text.Encoding.UTF8.GetString(chars);
            return output;
        }

"It is never too late to be what you might have been"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.