XSLT Transformations with the XslTransform Class (C#)

You can use the XslTransform class to transform XML data using an Extensible Stylesheet Language for Transformations (XSLT) style sheet. XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must use the namespace http://www.w3.org/1999/XSL/Transform.
 
The following code example loads an XSLT style sheet, reads a file called mydata.xml into an XPathDocument, and performs a transformation on the data on a fictitious file called myStyleSheet.xsl, sending the formatted output to the console.
 
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
public class Sample
{
    private const String filename = "mydata.xml";
    private const String stylesheet = "myStyleSheet.xsl";
    public static void Main()
    {
    XslTransform xslt = new XslTransform();
    xslt.Load(stylesheet);
    XPathDocument xpathdocument = new
    XPathDocument(filename);
    XmlTextWriter writer = new XmlTextWriter(Console.Out);
    writer.Formatting=Formatting.Indented;
    xslt.Transform(xpathdocument, null, writer, null);   
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: