XSLT编译错误使用XslCompiledTransform.Load当间接地从一个应用程序调用(X

2019-10-21 18:26发布

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

下面是C#代码: (click_me)

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

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

下面是我用的是典型的XSL代码:

<?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>

和XML内容:

<?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>

Answer 1:

我希望能与分机通话功能(扩展对象,传递给改造的方法)取代内嵌脚本会解决这个问题。

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



文章来源: XSLT compile error when using XslCompiledTransform.Load indirectly called from an application
标签: c# .net xslt