1using System.Xml;
2using System.Xml.Xsl;
3using System.Xml.XPath;
4using System.IO;
5
6//Create XPathDocument from the source string passed in.
7 StringReader SourceData = new StringReader(xml);
8 XPathDocument XmlSourceData = new XPathDocument(SourceData);
9 SourceData.Close();
10
11 //Create XPathDocument for stylesheet from the above string
12 StringReader StyleSheetData = new StringReader(Sb.ToString());
13 XPathDocument XslMasterDoc = new XPathDocument(StyleSheetData);
14 StyleSheetData.Close();
15
16 //Create a navigator for the source document. There is information we need
17 //to extract from it before we do the transform.
18 XPathNavigator XmlSourceNav = XmlSourceData.CreateNavigator();
19
20 //Create transform object
21 XslTransform XslDoc = new XslTransform();
22
23 //Create stream to fill with the transformed output
24 MemoryStream ms = new MemoryStream();
25
26 //Load the xslt and do the transform
27 XmlUrlResolver resolver = new XmlUrlResolver();
28 XslDoc.Load(XslMasterDoc, resolver, Assembly.GetExecutingAssembly().Evidence);
29 XslDoc.Transform(XmlSourceData, null, ms, resolver);
30
31 StreamReader sr = new StreamReader(ms);
32 ms.Seek(0, SeekOrigin.Begin);
33 string returnValue = sr.ReadToEnd();
34
35 return System.Web.HttpContext.Current.Server.HtmlDecode( returnValue );