3

Has anyone got XSLT3 transforms working in .NET Core 2.x+ in 2019?

Seems that the request to MS for XSLT2/3 support hasn't moved forwards, and the Saxon people have other priorities, especially given the IKVM closedown.

Are there any other alternatives for in-process XSLT transformation? At the moment, it seems my only choice is to wrap something up via an external service or some undesirable (for us) COM-style approach that would involve lots of marshalling of data, hurting performance.

user426445
  • 324
  • 2
  • 15

3 Answers3

2

Unfortunately IKVM has never supported .NET Core, so the .NET version of Saxon cannot be made to work in that environment. In Saxonica we've been exploring alternative avenues for .NET support, but we haven't found anything remotely promising. (Anyone fancy doing a Kotlin implementation for .NET?)

I don't know what's possible using XMLPrime or Exselt, both of which target .NET.

2021 Update

Saxonica now ships SaxonCS on .NET 5, this product is built by converting the Java code of SaxonJ to C# source code using a custom transpiler.

Michael Kay
  • 147,186
  • 10
  • 83
  • 148
2

There is one way how to use Saxon on .NET Core: via Transform.exe running as a process.

You can use code similar to this:

/// <summary>Transform XML inputFile using xsltFile and parameters. Save the result to the outputFile.</summary>

public void Transform(string inputFile, string outputFile, string xsltFile, NameValueCollection parameters)
{
//Search for the instalation path on the system
string path = GetInstalPath(@"Software\Saxonica\SaxonHE-N\Settings", "InstallPath");
string exePath = Path.Combine(path, "bin", "Transform.exe");

string parametersCmd = null;

//Set indicidual parameters
foreach (string parameter in parameters)
{
    parametersCmd += String.Format("{0}={1} ", parameter, parameters[parameter]);
}

//set arguments for Transform.exe
string arguments = string.Format("-s:\"{1}\" -xsl:\"{0}\" -o:\"{3}\" {2}", xsltFile, inputFile, parametersCmd, outputFile);

//https://stackoverflow.com/questions/5377423/hide-console-window-from-process-start-c-sharp
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = exePath;
startInfo.Arguments = arguments;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;

int waitingTime = 5 * 60 * 1000; //5 minutes; time in milliseconds

Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;

try
{
    processTemp.Start();
    processTemp.WaitForExit(waitingTime);
}
catch (Exception e)
{
    throw;
}

}

static string GetInstalPath(string comName, string key)
{
RegistryKey comKey = Registry.CurrentUser.OpenSubKey(comName);
if (comKey == null)
    return null;
string clsid = (string)comKey.GetValue(key);
return clsid;
}
0

SaxonCS EE has been released and works with .NET 5 and .NET 6 (RC/preview) and that way allows using XSLT 3, XPath 3.1 and XQuery 3.1 with .NET Core. It is only available under a commercial license however, but you can test it with a trial license, download from Saxonica is at https://www.saxonica.com/download/dotnet.xml, also on NuGet as https://www.nuget.org/packages/SaxonCS/.

Martin Honnen
  • 149,505
  • 6
  • 83
  • 100