XslTransform 与 XslCompiledTransform

发布于 2024-07-14 11:36:17 字数 193 浏览 9 评论 0原文

Microsoft 似乎已弃用 XslTransform,转而使用 XslCompiledTransform。 理论上,如果我在应用程序执行期间只进行一次转换,那么解释 XSLT(通过 XslTransform)不应该比编译它更快吗? 如果是这样,XslTransform 是否编写得如此糟糕,以至于对 XslCompiledTransform 所做的改进足以弥补它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

瞄了个咪的 2024-07-21 11:36:17

您可能希望查看 XslTransformXslCompiledTransform 之间记录的差异此处此处,然后自己做出决定

另外,在某些情况下XslTransform是比较不合规的。 在 XslCompiledTransform 的安全性方面做了更多工作。

因此,有很多理由应该考虑使用新的 XslCompiledTransform 而不是旧的 XslTransform,即使在仅运行转换的情况下也是如此一次,并且使用旧的 XslTransform 可能会稍微快一些。

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.

久随 2024-07-21 11:36:17

好吧,您可以看到 XslTransform 的(慢)运行时间与 XslCompiledTransform 的编译时间加上其(快)运行时间。 没有理论上的方法可以最终决定这种比较。

理论表明:运行时间取决于输入和所需的操作,而编译时间取决于 XSLT 的复杂性。 实践证实,对于简单的输入和复杂的 XSLT 一次性执行 XslTransform 肯定会更快。

然而,对于所有实际应用程序,您都需要 XslCompiledTransform,因为 XslTransform 已被弃用并且很可能包含永远无法修复的缺陷。 实际上,我有一些样式表在 XslTransform 下表现得很奇怪,但在 XslCompiledTransform 下运行得很好。

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.

千纸鹤 2024-07-21 11:36:17

无论如何,您都应该使用 XslCompiledTransform,因为 XslTransform 已被弃用,并且可能会从框架的未来版本中删除。

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

作为一个不相关的数据点,我只是浪费了几个小时来调试一个以前运行良好但现在不再运行的 XSLT。 结果证明 XSLT 没问题,问题是应用它的代码不久前从 XslTransform(工作完美)更新为 XslCompiledTransform(转换效果很差),从而触发了错误。

因此,对 XslTransform 被废弃感到不满意,因为我只需恢复代码即可使用它......:(

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

英雄似剑 2024-07-21 11:36:17

两者都有各自的优点和缺点。 我正在使用两者,但在不同的场景中。 我使用 XslTransform 将输出传递到 XML 控制变量并在文字控制中写入输出,但是当我需要传递到页面上的 XML 控件时,我需要 XslCompiledTransform。 这是因为两种方法的输出不同。

  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("<br>", "<BR/>");

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("<br>", "<BR/>");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文