Here I already explained once how it can be done in .Net Framework, with
Saxon-Se, and now here is experimental example in .Net Core.
Install NuGet package
SaxonHE12s9apiExtensions.
In .csproj add something like:
<ItemGroup>
<PackageReference Include="IKVM.Maven.Sdk" Version="1.8.2"/>
<MavenReference Include="net.sf.saxon:Saxon-HE" version="12.5"/>
<PackageReference Include="SaxonHE12s9apiExtensions" Version="12.5.9.4"/>
</ItemGroup>
Use this method to return result as a string which later you can convert to XML as I already explained
here:
using net.sf.saxon.s9api;
using net.liberty_development.SaxonHE12s9apiExtensions;
...
string ValidateXmlFile(string xmlFile, string xslFile)
{
Processor processor = new Processor();
DocumentBuilder builder = processor.newDocumentBuilder();
XsltTransformer xsltTransformer = processor.newXsltCompiler().Compile(new Uri(xslFile)).load();
var inputNode = builder.Build(new Uri(xmlFile));
xsltTransformer.setInitialContextNode(inputNode);
using var stringWriter = new StringWriter();
Serializer serializer = processor.NewSerializer(stringWriter);
xsltTransformer.setDestination(serializer);
xsltTransformer.transform();
return stringWriter.ToString();
}
Example download from
here.