XslTransform vs XslCompiledTransform
Asked Answered
A

5

6

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?

Africander answered 5/3, 2009 at 1:45 Comment(0)
P
4

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.

Percolation answered 5/3, 2009 at 14:41 Comment(2)
Note that on some complex transforms, XslCompiledTransform can be a lot slower than XslTransform, irrespective of the compilation overhead. I'm still working with MS technical support to figure out exactly what the problem is, but we have one case where performance of XslCompiledTransform is much worse. This seems to be a very case though, so in general I would definitely agree that XslCompiledTransform is preferableTriennium
@Andy, Yes, no one can confirm that XslCompiledTransform is faster for all, infinite number of transformations. We know from experience that it is generally faster.Percolation
O
2

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.

Opsis answered 5/3, 2009 at 8:59 Comment(0)
D
1

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

Dishevel answered 5/3, 2009 at 9:5 Comment(1)
It is flagged as obsolete nowTussle
H
1

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... :(

Hognut answered 9/9, 2013 at 15:2 Comment(0)
P
-1

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/>");
Planometer answered 1/8, 2014 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.