Question

XslTransform appears to have been deprecated by Microsoft in favor of XslCompiledTransform. Theoretically, if I was doing just one transform during the execution of my application, shouldn't interpreting the XSLT (through XslTransform) be faster than compiling it? If so, is XslTransform written so badly that the improvements made to XslCompiledTransform more than compensate for it?

Was it helpful?

Solution

You might want to see the documented differences between XslTransform and XslCompiledTransform here and here, and make the decision yourself.

In addition, there are some cases in which XslTransform is more incompliant. More work was done on security in XslCompiledTransform.

So, a lot of reasons one should consider using the new XslCompiledTransform instead of the old XslTransform, even in cases where the transformation will be run only once and could be slightly faster with the old XslTransform.

OTHER TIPS

Well, you have the (slow) running time of XslTransform vs. the compile time of XslCompiledTransform plus its (fast) running time. There is no theoretical way to decide this comparison conclusively.

Theory suggests: running times depend on input and required operations and compile time depends on complexity of the XSLT. Practice confirms that with trivial input and complex XSLT one time execution XslTransform is definitely be faster.

However, for all real applications you will want XslCompiledTransform if only for the fact that XslTransform is deprecated and may very well contain flaws that will never be fixed. I actually had some stylesheets behaving strangely under XslTransform and running perfectly under XslCompiledTransform.

As an unrelated data point, i just wasted a couple hours debugging an XSLT that used to work fine and no longer did. Turned out the XSLT was fine, the problem was that the code that applied it was updated from XslTransform (which worked perfectly) to XslCompiledTransform (which transforms it badly), a while ago, and that triggered the error.

So, not happy with XslTransform being Obsoleted, here, as i just had to revert the code to use it... :(

You should use XslCompiledTransform in any case since XslTransform is depreciated and may be removed from future versions of the framework.

Both have their own pros and cons. I am using both but in different scenario. I am using XslTransform to pass the output to a XML control variable and write output in literal control but when I need to pass to XML control on page then I need to XslCompiledTransform. This is because output of both methods are different.

  System.Web.UI.WebControls.Xml objXML = new System.Web.UI.WebControls.Xml();
        System.IO.StringWriter objTextWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objTextWriter);
        XslTransform objTrans = new XslTransform();
        objTrans.Load(HttpContext.Current.Server.MapPath(strXslFileName));
        objXML.TransformArgumentList = objArgsList;
        objXML.Transform = objTrans;
        objXML.Document = objOutputXml;
        objXML.RenderControl(objHtmlTextWriter);
        return objTextWriter.ToString();



 XslCompiledTransform objTrans = new System.Xml.Xsl.XslCompiledTransform();
        System.IO.StringWriter objStringReader = new System.IO.StringWriter();
        objTrans.Load(HttpContext.Current.Server.MapPath(strXslFileName));
        objTrans.Transform(objOutputXml, objArgsList, objStringReader);
        return objStringReader.ToString().Replace("&lt;br&gt;", "<BR/>");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top