Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web control like this:
<asp:Xml ID="XmlResult" runat="server" />
This is used to perform an XSLT transformation in c# code-behind like this:
XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("~/xslt/MyXsltFile.xslt"));
XmlResult.Transform = xslt;
XmlResult.TransformArgumentList = xslArgs; // these are created elsewhere
XmlResult.XPathNavigator = xd.CreateNavigator(); // xd is an XmlDocument()
The problem is that the ASP XML control expects an XltTransform object and this is deprecated (marked as obsolete) as from NET 2.0:
“The XslTransform class is obsolete in
the Microsoft .NET Framework version
2.0. The XslCompiledTransform class is the new XSLT processor.”
However, I can’t seem to figure out how to replace this to use an XslCompiledTransform object. Obviously you can just give XmlResult.Transform property an XslCompiledTransoform object as this won’t work. So presumably will have to replace the ASP Xml control with something else? A Literal? A Placeholder? But then what…? I just can’t seem to work out the best way of doing this.
Any help would be appreciated! Thanks.
I finally figured out this and thought I’d provide the answer in case it proves useful to others. Below is a small helper class that uses XsltCompiledTransform and also can cache the results. It was written specifically for caching Umbraco macros, but can be used in any situation, I believe.
}