Tuesday, September 06, 2011

Render(Parse) XML using XSLT

The requirement is to render xml data into a page.
We can perform this task by following ways:
1. Read xml file using C#.Net and iterate the xml node. At the time of iteration, render data from xml to page.
2. Use the XSL. In this approach, create .XSLT file, which store the formatting in the form of HTML/CSS. By using XSL, we can separate the data rending from the data itself.
Example to render (parse) xml using xslt:
Save given xml in to file called "myNavigation.xslt":


Now add following tag in your .ASPX page:

In the code behind file of .ASPX page (.ASPX.CS file), add following directive:
using System.Xml;
using System.Xml.Xsl;

After that,in the code behind file of .ASPX page (.ASPX.CS file), write following code in the Page_Load method:

string languageDetails =
XmlDocument myNavigationDoc = new XmlDocument();

XslTransform myNavigationTransform = new XslTransform();

this.myNavigationControl.Document = myNavigationDoc;
this.myNavigationControl.Transform = myNavigationTransform;



Robert P. Calfee said...

I am William..I just browsing through some blogs and came across yours!Excellent blog, good to see someone actually uses for quality posts.Your site kept me on for a few minutes unlike the rest :)Keep up the good work!Thanks for sharing a important information on sharepoint

Priya Sethuraman said...

I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.
Hadoop Training in Chennai
Hadoop Training
Best Hadoop Training in Chennai
Best Hadoop Training Institute in Chennai

About Me

My photo
Based in Bangalore, INDIA, Amit is a MCC. He has an MCA from the U.P.T.U., INDIA and holds Microsoft certifications including SharePoint 2007/2010/2013. He is an contributor to MSDN and http://amitkumarmca04.blogspot.com/. Amit have experience in SharePoint,ASP.Net with C#, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.