Tuesday, September 19, 2006

XML and XSLT transformation using C#.NET

With XML Document you can illustrate data hierarchically without caring about the later output format, and with XSL-Transformations you have the ability to convert the data content of that XML document into various formats such as text, xml, html etc. XSLT, the extensible style sheet language for transformations, is a language that provides the mechanism to transform and manipulate XML data. It is used to transform XML documents into another documents, for example other XML document, HTML document or text document. XSLT processors parse the input XML document, as well as the XSLT style sheet and then process the instructions found in the XSLT style sheet, using the elements from input XML document.

Here in this sample I have explained you the XML and XSLT transformation using C#.NET 2.0.
C#.NET 2.0. Before transformation my tool will look like this...








After you select your XSLT and XML files when you click on the preview button the output is displayed as HTML in the webBrowser control.



For more see the sample code...


XPathDocument xmlFileDoc = new XPathDocument(txtxmlfilepath.Text.ToString());
XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
XslCompiledTransform XSLpreview = new XslCompiledTransform();
XSLpreview.Load(txtxslfilepath.Text.ToString());
XSLpreview.Transform(xmlFileDoc, null, myWriter);
myWriter.Close();
webBrowser1.Navigate(@"C:\result.html");

Download The Sample Solution

No comments:

ASP.NET MVC - Sport Facility Booking system

  The project relies on some external service providers. Thus accessing them via their API requires authentication. An API Key need to be su...