XslTransform vs XslCompiledTransform

XslTransform seems to be deprecated by Microsoft in favor of XslCompiledTransform. Theoretically, if I were to perform only one conversion during the execution of my application, should XSLT (via XslTransform) be interpreted faster than compiling it? If so, is XslTransform written so poorly that the improvements made to XslCompiledTransform more than make up for this?

+6
xslt
source share
5 answers

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

In addition, there are some cases where XslTransform is no longer compatible. XslCompiledTransform has done a lot of security work.

So, for many reasons, you should use the new XslCompiledTransform instead of the old XslTransform , even in cases where the conversion will be performed only once and may be slightly faster with the old XslTransform.

+4
source share

Well, you have XslTransform (slow) runtime compared to XslCompiledTransform compilation time and its (fast) runtime. There is no theoretical way to finally solve this comparison.

The theory suggests: runtime depends on input and required operations, and compilation time depends on XSLT complexity. Practice confirms that with trivial input and complex XSLT, a single execution of XslTransform will certainly be faster.

However, for all real-world applications, you will need XslCompiledTransform, if only because XslTransform is outdated and may very contain flaws that will never be fixed. I actually had some styles that behave strangely under XslTransform and work fine under XslCompiledTransform.

+2
source share

As an unrelated data point, I just spent a couple of hours debugging XSLT, which worked fine and didn't work anymore. It turned out that XSLT was in order, the problem was that the code that used it was updated from XslTransform (which worked fine) with XslCompiledTransform (which transforms it badly), and this caused an error.

So, not happy that XslTransform was Obsoleted, here, because I just needed to return the code to use it ... :(

+2
source share

You should use XslCompiledTransform anyway, as XslTransform is depreciating and may be removed from future versions of the framework.

+1
source share

Both have their pros and cons. I use both options, but in a different scenario. I use XslTransform to pass the output to an XML control variable and write the output to a literal control, but when I need to go to the XML control on the page, then I need XslCompiledTransform. This is because the output of both methods is 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/>"); 
0
source share

All Articles