WARNING: By the way this only works for simple 'standalone' XSL transforms. For chained XSLs (where main XSL includes additional XSL's using the
public string TransformXml(string xml, string xsl)
{
string responseXml = string.Empty;
//Read XML
TextReader iXmlReader = new StringReader(xml);
XmlTextReader iXmlText = new XmlTextReader(iXmlReader);
XPathDocument iXPathDocument = new XPathDocument(iXmlText);
//Read XSL
TextReader iXslReader = new StringReader(xsl);
XmlTextReader iXslText = new XmlTextReader(iXslReader);
//Get ready
XslTransform xslt = new XslTransform();
xslt.Load(iXslText);
StringBuilder sb = new StringBuilder();
TextWriter tw = new StringWriter(sb);
//Transform
xslt.Transform(iXPathDocument, null, tw);
responseXml = sb.ToString();
return responseXml;
}
No comments:
Post a Comment
Please use your common sense before making a comment, and I truly appreciate your constructive criticisms.