Reputation: 51
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?
Upvotes: 1
Views: 5618
Reputation: 167436
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));
Upvotes: 1
Reputation: 163262
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.
Upvotes: 2