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

2
  • 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. Commented Oct 19, 2017 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. Commented Oct 20, 2017 at 15:30

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Gotcha, so if I convert this to say, javascript, it should be able to execute then?
Correct - you can find an example here: msdn.microsoft.com/en-us/library/ms256042(v=vs.110).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.