I am currently trying to figure out how I can add content to a web page, which has been transformed from an XML document into HTML by an XSLT document. The solution I have thought of looks like this...
Code:
public static LiteralControl XmlFileTransform(string xmlfile, string xslfile)
{
XslTransform xslt;
XPathDocument xml;
StringWriter writer = new StringWriter();
try
{
xml = new XPathDocument(new XmlTextReader(xmlfile));
xslt = new XslTransform();
xslt.Load(xslfile);
xslt.Transform(xml, null, writer, null);
return new LiteralControl(writer.ToString());
}
catch(Exception e)
{
writer.Write(e.Message);
}
return null;
}
Is there a better way?
In the above solution I turn the generated HTML into a LiteralControl and then return this. I am not sure if this is the best solution for adding the generated output to the page dynamically.
What do you think?
Is it possible to make a transformation of part of a document? Say I have selected only one node and I have made an XSLT document that matches this one node.
Thanks, Jacob.