So I retrieve an XML and XSLT as strings from the DB then used my custom HTML helper called RenderXml
to render. The problem is that it is not rendering properly. In my HTML helper is where I do the transformation
public static HtmlString RenderXml(this HtmlHelper helper, string theXml, string theXslt)
{
XDocument xmlTree = XDocument.Parse(xmlPath);
XDocument newTree = new XDocument();
using (XmlWriter writer = newTree.CreateWriter())
{
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(new StringReader(xsltPath)));
// Execute the transform and output the results to a writer.
xslt.Transform(xmlTree.CreateReader(), writer);
return new HtmlString(newTree.ToString());
}
}
in my CSHTML I do it like this
<div id="results">@Html.RenderXml(Model.theXmlFile, Model.theXSLFile,)</div>
When I try to return new HtmlString(newTree.ToString());
I get a blank, and when I try to return new HtmlString(writer.ToString());
I get this System.Xml.XmlWellFormedWriter
on the page. Do anybody know what I am doing wrong? I got my code from the example here. I have also looked into this one and it works great except I do not use a URI, and when I try to modify it to use XDocument complains about missing parameters, so I stayed away from it. Any ideas why he transformation is not working?