1

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

JasonWH
  • 179
  • 2
  • 17
  • 1
    To be clear, you're calling the ActiveX MSXML 6.0 from a C# program in order to run a transformation? If so, you might want to do XSL directly in C#, using XmlDocument or XDocument. – William Walseth Oct 19 '17 at 22:58
  • No I have an XSLT transformation being completed by a different piece of software that uses the MSXSL6.0 processor, just trying to leverage that. – JasonWH Oct 20 '17 at 15:30

1 Answers1

2

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).

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • Gotcha, so if I convert this to say, javascript, it should be able to execute then? – JasonWH Oct 20 '17 at 15:26
  • Correct - you can find an example here: https://msdn.microsoft.com/en-us/library/ms256042(v=vs.110).aspx – Pawel Oct 20 '17 at 16:26