.NET - XSLT on XML
CodeKeep C# Feed Maggio 1st, 2008
Description: How to xsl transform xml in .NET
Link: http://www.codekeep.net/snippets/943f0858-d671-4e48-8cef-4064dba6dcd7.aspx
using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.IO; //Create XPathDocument from the source string passed in. StringReader SourceData = new StringReader(xml); XPathDocument XmlSourceData = new XPathDocument(SourceData); SourceData.Close(); //Create XPathDocument for stylesheet from the above string StringReader StyleSheetData = new StringReader(Sb.ToString()); XPathDocument XslMasterDoc = new XPathDocument(StyleSheetData); StyleSheetData.Close(); //Create a navigator for the source document. There is information we need //to extract from it before we do the transform. XPathNavigator XmlSourceNav = XmlSourceData.CreateNavigator(); //Create transform object XslTransform XslDoc = new XslTransform(); //Create stream to fill with the transformed output MemoryStream ms = new MemoryStream(); //Load the xslt and do the transform XmlUrlResolver resolver = new XmlUrlResolver(); XslDoc.Load(XslMasterDoc, resolver, Assembly.GetExecutingAssembly().Evidence); XslDoc.Transform(XmlSourceData, null, ms, resolver); StreamReader sr = new StreamReader(ms); ms.Seek(0, SeekOrigin.Begin); string returnValue = sr.ReadToEnd(); return System.Web.HttpContext.Current.Server.HtmlDecode( returnValue );






