Transforming Xml using an Xsl stylesheet in .net 2

Here is a simple way to transform an xml document using xsl in .net 2.0. Note that the class name has changed from XslTransform to XslCompiledTransform between .net 1.1 and .net 2.0.

XmlDocument xmlDoc = new XmlDocument();
XslCompiledTransform xslTransform = new XslCompiledTransform();
System.Text.StringBuilder builder = new System.Text.StringBuilder();
System.IO.StringWriter writer = new System.IO.StringWriter(builder);
xslTransform.Transform(xmlDoc, new XmlTextWriter(writer));
string transformedString = builder.ToString();

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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: