/ Published in: C#
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
namespace [[Name Space]]
{
public class [[Class Name]]
{
/// <summary>
/// Transforms the supplied xml using the supplied xslt and returns the
/// result of the transformation
/// </summary>
/// <param name="xml">The xml to be transformed</param>
/// <param name="xslt">The xslt to transform the xml</param>
/// <returns>The transformed xml</returns>
public string TransformXml(string xml, string xslt)
{
// Simple data checks
if (string.IsNullOrEmpty(xml))
{
}
if (string.IsNullOrEmpty(xslt))
{
}
// Create required readers for working with xml and xslt
// Create required writer for output
// Create a XslCompiledTransform to perform transformation
try
{
xsltTransform.Transform(xmlReader, transformedXml);
}
catch (XmlException xmlEx)
{
// TODO : log - "Could not load XSL transform: \n\n" + xmlEx.Message
throw;
}
catch (XsltException xsltEx)
{
// TODO : log - "Could not process the XSL: \n\n" + xsltEx.Message + "\nOn line " + xsltEx.LineNumber + " @ " + xsltEx.LinePosition)
throw;
}
catch (Exception ex)
{
// TODO : log
throw;
}
return stringWriter.ToString();
}
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                