Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

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

RSS
Modified on Sun, Jul 05, 2009, 12:04 AM by Administrator Categorized as XML, XSL, and XPath, ┬Ě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();

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2017, Patrick Jasinski.