They are not many solutions out there in .NET that allow you to combine the power of XQuery with a C# API. The built-in XSLT support in .NET is very limited and only supports the XSLT 1.0 specifications.
One of the best options you have is Saxon, a powerful XSLT and XQuery processor. The only disadvantage of this tool is that the syntax is very JAVA oriented, which makes it sometimes counterintuitive for .NET developers.
A sample:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xslt = new FileInfo(@"C:\stylesheet.xslt"); | |
var input = new FileInfo(@"C:\input.xml"); | |
var output = new FileInfo(@"C:\output.xml"); | |
var processor = new Processor(); | |
var compiler = processor.NewXsltCompiler(); | |
var executable = compiler.Compile(new Uri(xslt.FullName)); | |
var destination = new DomDestination(); | |
using(var inputStream = input.OpenRead()) | |
{ | |
var transformer = executable.Load(); | |
transformer.SetInputStream(input, new Uri(input.DirectoryName)); | |
transformer.Run(destination); | |
} | |
destination.XmlDocument.Save(output.FullName); |