I just learned about XSL and XSLT a few days ago and now I'm trying to put it to work based on a question I had earlier today (want to have formated XML displayed on my website).
Here is the code I'm trying (in a View):
XDocument xmlInput = XDocument.Parse(item.Action);
XDocument htmlOutput = new XDocument();
using (System.Xml.XmlWriter writer = xmlInput.CreateWriter())
{
// Load Transform
System.Xml.Xsl.XslCompiledTransform toHtml = new System.Xml.Xsl.XslCompiledTransform();
string path = HttpContext.Current.Server.MapPath("~/App_Data/xmlverbatimwrapper.xsl");
toHtml.Load(path);
// Execute
toHtml.Transform(xmlInput.CreateReader(), writer);
}
Response.Write(htmlOutput.ToString());
And it's giving me this error:
[InvalidOperationException: This operation would create an incorrectly structured document.]
Not sure if it's along the right lines, but I've tried modifying the writers settings so it can produce fragmented xml files with no luck (since it's readonly). Any ideas to get this working? Perhaps I'm going about completely the wrong approach? :)
Thanks for your help!