Posted By

Meander365 on 08/12/09


Tagged

xslt xml c aspnet transform


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
tzerb
danfinrud55


Using XSLT to Transform XML Using C# ASP.NET


 / Published in: C#
 

  1. using System.Xml;
  2. using System.Xml.Xsl;
  3. using System.Xml.XPath;
  4. using System.IO;
  5.  
  6. private string ApplyXSLTransformation()
  7. {
  8. string strHtml;
  9.  
  10. string strXstFile = Server.MapPath("my-xsl.xslt");
  11. XslCompiledTransform x = new XslCompiledTransform();
  12.  
  13. // Load the XML
  14. XPathDocument doc = new XPathDocument(Server.MapPath("my-xml.xml"));
  15.  
  16. // Load the style sheet.
  17. XslCompiledTransform xslt = new XslCompiledTransform();
  18. xslt.Load(strXstFile);
  19. MemoryStream ms = new MemoryStream();
  20. XmlTextWriter writer = new XmlTextWriter(ms, Encoding.ASCII);
  21. StreamReader rd = new StreamReader(ms);
  22. xslt.Transform(doc, writer);
  23. ms.Position = 0;
  24. strHtml = rd.ReadToEnd();
  25. rd.Close();
  26. ms.Close();
  27. return strHtml;
  28. }

Report this snippet  

You need to login to post a comment.