1

I am having an .NET Core 3.1 Application and an XSLT 2.0 Script. The script should now be executed by the Application.

First I tried:

//Create a new XslCompiledTransform and load the compiled transformation.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(typeof(Transform));

        // Execute the transformation and output the results to a file.
        xslt.Transform("books.xml", "discount_books.html");

But this just seems to work on .NET Framework and just for XSLT 1.0.

No I found the NuGet-Package Saxon-HE-fixedrefs, which should be compatible to .NET core according to the description. But when compiling I get an error in my first line

Saxon.Api.Processor proc = new Saxon.Api.Processor();

"System.TypeInitializationException: "The type initializer for 'net.sf.saxon.Configuration' threw an exception."

FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. "

Is there any workaround for this?

wonea
  • 4,783
  • 17
  • 86
  • 139
Gigalodon
  • 51
  • 1
  • 8
  • See https://stackoverflow.com/a/58931196/252228 for XmlPrime as an option, at least technically, you would need to get in touch with them about licensing or future releases. As for Saxon, I don't know what that fixedrefs project tried to fix, but my understanding is that Saxon on .NET relies on IKVM which was developed for the .NET framework and is not compatible with .NET core. Of course, within ASP.NET, it should be possible to write an ASP.NET framework Web API that your ASP.NET Core pages could use like another rest API. – Martin Honnen Aug 13 '20 at 12:55
  • Saxon-HE-fixedrefs was last released in 2016 and was said to work with "the .NET Core CLI tools 1.0.0-**preview2**". Why do you expect it to work with the current version of .NET Core, 4 years later? – Dimitre Novatchev Aug 14 '20 at 02:37

2 Answers2

2

You will have to contact the package owner, Max Toro, to find out why Saxon-HE-fixedrefs is not working as described. Although the package description claims it to be unmodified Saxonica code, it is not distributed or supported by Saxonica, and as far as we in Saxonica are concerned, we believe that Saxon does not work on .NET Core.

We're aware of the need for a version of Saxon that runs on .NET Core, and are pursuing various avenues to achieve this, but the IKVM technology we rely on doesn't support Core, and the original developer Jeroen Frijters is no longer maintaining it, so we can't make any promises.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Jus to note, Max Toro is not the owner of https://www.nuget.org/packages/Saxon-HE-fixedrefs/, it is https://www.nuget.org/profiles/tflanitzer. Max Toro provided NuGet packages of Saxon HE for the .NET framework before Saxonica officially took over. – Martin Honnen Aug 13 '20 at 17:29
1

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

As XSLT 3.0 implemented by SaxonCS is backwards compatible to XSLT 2.0 you want to run it should be no problem to use SaxonCS to run XSLT 2.0 with .NET Core.

Also IKVM has been updated to allow building .NET 3.1 or later (i.e. .NET 6) code; I have tried to use it to cross-compile Saxon HE 11 Java to .NET 6 and it has worked out. You can find a command line runner/dotnet tool on NuGet at https://www.nuget.org/packages/SaxonHE11NetXslt/.

Additionally I have created a samples project on GitHub that uses an extension method library (repository at https://github.com/martin-honnen/SaxonHE11s9apiExtensions) to ease the use of the Saxon HE 11 s9api API from .NET code.

Sample .NET 6 code would be

using net.sf.saxon.s9api;
using net.liberty_development.SaxonHE11s9apiExtensions;
using System.Reflection;

// force loading of updated xmlresolver
ikvm.runtime.Startup.addBootClassPathAssembly(Assembly.Load("org.xmlresolver.xmlresolver"));
ikvm.runtime.Startup.addBootClassPathAssembly(Assembly.Load("org.xmlresolver.xmlresolver_data"));

var processor = new Processor(false);

Console.WriteLine($"{processor.getSaxonEdition()} {processor.getSaxonProductVersion()}");

var xslt30Transformer = processor.newXsltCompiler().Compile(new Uri("https://github.com/martin-honnen/martin-honnen.github.io/raw/master/xslt/processorTestHTML5Xslt3InitialTempl.xsl")).load30();

xslt30Transformer.callTemplate(null, processor.NewSerializer(Console.Out));
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110