我试图使用MSXSL6.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 我做了一些研究,发现默认情况下系统程序集包括在内,所以我删除了装配线,并尝试再次运行它。THis时间到了:
External XSLT processing started...
Error occurred while compiling blah blah blah
Code: 0x80004005
Keyword msxsl:script may not contain msxsl:using.
...done 我试图搜索这个特定的错误,但没有发现任何有用的东西。任何帮助都将不胜感激。
谢谢
发布于 2017-10-20 00:16:08
如果使用msxsl处理器,您将无法运行嵌入在Xslt中的C#代码。msxsl使用的是原生Xml/Xslt处理器,它不会为您引导CLR (托管运行时)。当使用原生Xml堆栈时,可以在msxsl:script内部使用vbscript/jscript,但是C#/VB.NET只能与托管Xslt处理器(即XsltCompiledTransform)一起使用。
https://stackoverflow.com/questions/46839859
复制相似问题