Return to Snippet

Revision: 16676
at August 12, 2009 05:54 by Meander365


Initial Code
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;

private string ApplyXSLTransformation()
{
    string strHtml;
 
    string strXstFile = Server.MapPath("my-xsl.xslt");
    XslCompiledTransform x = new XslCompiledTransform();
 
    // Load the XML 
    XPathDocument doc = new XPathDocument(Server.MapPath("my-xml.xml"));
 
    // Load the style sheet.
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load(strXstFile);
    MemoryStream ms = new MemoryStream();
    XmlTextWriter writer = new XmlTextWriter(ms, Encoding.ASCII);
    StreamReader rd = new StreamReader(ms);
    xslt.Transform(doc, writer);
    ms.Position = 0;
    strHtml = rd.ReadToEnd();
    rd.Close();
    ms.Close();
    return strHtml;
}

Initial URL

                                

Initial Description

                                

Initial Title
Using XSLT to Transform XML Using C# ASP.NET

Initial Tags
xml, c, aspnet

Initial Language
C#