XSLT编译错误使用XslCompiledTransform.Load时,从应用程序间接调用 [英] XSLT compile error when using XslCompiledTransform.Load indirectly called from an application

查看:429
本文介绍了XSLT编译错误使用XslCompiledTransform.Load时,从应用程序间接调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#编写的组件。除此之外它执行XSL转换就可以收集XML数据。当我使用一个使用它工作得很好组件的另一个C#项目测试此功能。然而,当我的组件导出为一个COM组件,并尝试使用该功能从失败上使用XSLT的XslCompiledTransform.Load命令编译出错的应用程序。

下面是C#code:(click_me)

和我收到的错误被复制的文件。请它在这里找到:(click_me)

随着模板的数量还包括C#脚本意味着一些先进的计算,这XSLT是不能的XSLT文件。

下面是我用的是典型的XSL code:

 < XML版本=1.0编码=UTF-8&GT?;
< XSL:样式版=1.0的xmlns:XSL =htt​​p://www.w3.org/1999/XSL/Transform
    的xmlns:msxsl =瓮:架构 - 微软COM:XSLT排除-result- prefixes =msxsl的xmlns:CS =金塔:CS>
  < XSL:输出方法=XML缩进=无/>

  < msxsl:脚本语言=C#implements- preFIX =CS>
    <![CDATA [
     私人静态字符串[] formats_datetime =新的String []
     {
        MM / DD / YYYY HH:MM:SS
     };

     公共字符串DATE_ADD(字符串date_str,串time_span_par)
      {
            日期时间DATE_VALUE;
            时间跨度time_span_var = TimeSpan.Parse(time_span_par);

            DateTime.TryParseExact(date_str,formats_datetime,新的全球:: System.Globalization.CultureInfo(EN-US),全球:: System.Globalization.DateTimeStyles.None,出DATE_VALUE);
            DATE_VALUE = date_value.Add(time_span_var);
            字符串临时= date_value.ToString(MM / DD / YYYY HH:MM:SS);
            返回(临时);
      }
]]≥
  < / msxsl:脚本>

  < XSL:模板匹配=@ * |节点()>
    < XSL:复制>
      < XSL:申请-模板选择=@ * |节点()/>
    < / XSL:复制>
  < / XSL:模板>

  < XSL:模板匹配=date_node>
    < XSL:变量名=date_in>
      < XSL:value-of的选择= />中。
    < / XSL:变量>
    < XSL:变量名=期间>
      < XSL:value-of的选择=06:00:00/>
    < / XSL:变量>
    < XSL:复制>
      < XSL:选择=价值的CS:DATE_ADD($ date_in,$期)/>
    < / XSL:复制>
  < / XSL:模板>
< / XSL:样式>
 

和XML内容:

 < XML版本=1.0编码=UTF-8&GT?;
<根>
  <节点1> 34  - ; /节点1>
  <节点2> 23℃/节点2>
  < date_node> 12/31/2020 23:59:59< / date_node>
  <孩子>
    <节点1>文字< /节点1>
    < date_node> 12/31/2020 23:59:59< / date_node>
    < grand_child>
      < date_node> 12/31/2020 23:59:59< / date_node>
    < / grand_child>
  < /儿童>
< /根>
 

解决方案

我希望能与调用扩展功能(扩展对象的方法,传递给改造)更换内嵌脚本会解决这个问题。

建议使用preference扩展功能上内嵌脚本。 如果内嵌脚本中广泛使用IIS服务器的环境中,这可能会导致(这已被观察到的)内存泄漏,最终关闭服务器。这是因为XslCompiledTransform编译脚本转换为动态的dll文件无法卸载,直到IIS被回收。

I have a component written in C#. Among other things it performs XSL transform on XML data it collects. When I test this feature using another C# project that uses the component it works just fine. However when I export the component as a COM component and try to use this feature from an application it fails on the XslCompiledTransform.Load command with an XSLT compile error.

Here is the C# code: (click_me)

And the error I am getting is copied in a file. Please find it here: (click_me)

The XSLT file along with the number of templates also consists of "C# script" meant for some advanced calculations, which XSLT isn't capable of.

Here is the typical XSL code that I use:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:cs="urn:cs">
  <xsl:output method="xml" indent="no"/>

  <msxsl:script language="C#" implements-prefix="cs">
    <![CDATA[
     private static string[] formats_datetime = new string[]
     {
        "MM/dd/yyyy HH:mm:ss"
     };

     public string date_add(string date_str, string time_span_par)
      {
            DateTime date_value;
            TimeSpan time_span_var = TimeSpan.Parse(time_span_par);

            DateTime.TryParseExact(date_str, formats_datetime, new global::System.Globalization.CultureInfo("en-US"), global::System.Globalization.DateTimeStyles.None, out date_value);
            date_value = date_value.Add(time_span_var);
            string temp = date_value.ToString("MM/dd/yyyy HH:mm:ss");
            return(temp);
      }
]]>
  </msxsl:script>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@*| node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="date_node">
    <xsl:variable name="date_in">
      <xsl:value-of select="."/>
    </xsl:variable>
    <xsl:variable name="period">
      <xsl:value-of select="'06:00:00'"/>
    </xsl:variable>
    <xsl:copy>
      <xsl:value-of select="cs:date_add($date_in, $period)"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

And the XML content:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <node1>34</node1>
  <node2>23</node2>
  <date_node>12/31/2020 23:59:59</date_node>
  <child>
    <node1>text</node1>
    <date_node>12/31/2020 23:59:59</date_node>
    <grand_child>
      <date_node>12/31/2020 23:59:59</date_node>
    </grand_child>
  </child>
</root>

解决方案

I hope that replacing the inline scripts with calls to extension functions (methods of an extension object, that is passed to the transformation) will solve the problem.

It is recommended to use extension functions in preference over inline scripts. If inline scripts are used extensively in an IIS server environment, this can result (and this has been observed) to memory leaks that eventually bring down the server. This is because the XslCompiledTransform compiles the scripts into dynamic dlls that cannot be unloaded until IIS is recycled.

这篇关于XSLT编译错误使用XslCompiledTransform.Load时,从应用程序间接调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆