Displaying an XSL Transformation in a Web Browser Control - .Net Framework

The following code demonstrates how to transform an XML file with an XSL file and display the result of the transformation in a WebBrowser control. You can convert code between C# and VB.NET at this website.

string xmlFile = @"c:\Alerts.xml";
string xslFile = @"c:\Alerts.xsl";
XslCompiledTransform xslDocument = new XslCompiledTransform();
xslDocument.Load(xslFile);
StringWriter stringWriter = new StringWriter();
XmlWriter xmlWriter = new XmlTextWriter(stringWriter);
xslDocument.Transform(xmlFile, xmlWriter);
uxWebBrowser.DocumentText = stringWriter.ToString();

Similarly, the following code demonstrates how to transform XML data. You can convert code between C# and VB.NET at this website.

//- Load XSL Transformation -----------------------------------------------------------
string xslFile = "~/Search.xsl";
xslFile = Server.MapPath(xslFile);
XslCompiledTransform xslDocument = new XslCompiledTransform();
xslDocument.Load(xslFile);

//- Load XML Data ---------------------------------------------------------------------
string result = Globals.Database.Search(searchFor);
StringReader stringReader = new StringReader(result);
XmlReader xmlReader = new XmlTextReader(stringReader);
StringWriter stringWriter = new StringWriter();
XmlWriter xmlWriter = new XmlTextWriter(stringWriter);

//- Transform and Output Data ---------------------------------------------------------
xslDocument.Transform(xmlReader, xmlWriter);
uxSearchResultsLabel.Text = stringWriter.ToString();