Reputation: 179
I am attempting to execute an XML transform using the MSXSL 6.0 processor, and the XSLT file has a C# method at the top of it. Here is the sample XSLT I'm using:
<?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>
Initially I had a line just after the msxsl:script tag like this:
<msxsl:assembly name="System.DateTime" />
When attempting to run the transform I received an error here:
External XSLT processing started...
Error occurred while compiling blah blah blah
Code: 0x80004005
Keyword msxsl:script may not contain msxsl:assembly.
...done
I did a little research and found that the System assembly is included by default, so I removed the assembly line and tried to run it again. THis time I got:
External XSLT processing started...
Error occurred while compiling blah blah blah
Code: 0x80004005
Keyword msxsl:script may not contain msxsl:using.
...done
I've tried searching up this particular error, but have not found anything very useful. Any help would be appreciated.
Thanks
Upvotes: 1
Views: 1393
Reputation: 31610
You won't be able to run C# code embedded in Xslt if you are using the msxsl processor. msxsl is using native Xml/Xslt processor which will not bootstrap CLR (managed runtime) for you. You can use vbscript/jscript inside msxsl:script
when using the native Xml stack but C#/VB.NET can be used only with the managed Xslt processor (i.e. XsltCompiledTransform
).
Upvotes: 2