在带有 MSXSL 6.0 的 XSLT 中使用 C#

Using C# in XSLT with MSXSL 6.0

我正在尝试使用 MSXSL 6.0 处理器执行 XML 转换,XSLT 文件的顶部有一个 C# 方法。这是我正在使用的示例 XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts">
    <msxsl:script language="C#" implements-prefix="user">
        <msxsl:using namespace="System.DateTime"/>
        <msxsl:using namespace="System.TimeZone"/>
        <![CDATA[
            public string GetLocalTime(string returnPart, string utcTime){
                string[] timeList = utcTime.Split(':');
                string endString = string.Join(":", timeList.Take(3));
                DateTime result = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Parse(endString));
                if(returnPart == "Date")
                {
                    return result.ToString("MM/dd/yyyy");
                }
                else if(returnPart == "Time")
                {
                    return result.ToString("HH:mm:ss");
                }
                else
                {
                    return result.ToString();
                }
            }           
        ]]>
    </msxsl:script>

最初我在 msxsl:script 标签之后有一行是这样的:

<msxsl:assembly name="System.DateTime" />

尝试 运行 转换时,我在此处收到错误消息:

External XSLT processing started...

Error occurred while compiling blah blah blah

    Code:   0x80004005
    Keyword msxsl:script may not contain msxsl:assembly.
    ...done 

我做了一些研究,发现系统程序集是默认包含的,所以我删除了程序集并再次尝试 运行。这次我得到了:

External XSLT processing started...

Error occurred while compiling blah blah blah

Code:   0x80004005
Keyword msxsl:script may not contain msxsl:using.
...done 

我已经尝试搜索这个特定的错误,但没有找到任何有用的信息。任何帮助将不胜感激。

谢谢

如果您使用的是 msxsl 处理器,您将无法 运行 在 Xslt 中嵌入 C# 代码。 msxsl 使用本机 Xml/Xslt 处理器,它不会为您 bootstrap CLR(托管 运行 时间)。使用本机 Xml 堆栈时,您可以在 msxsl:script 中使用 vbscript/jscript,但 C#/VB.NET 只能与托管 Xslt 处理器(即 XsltCompiledTransform)一起使用。