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>