|
using System;
|
|
using System.IO;
|
|
using System.Xml.Linq;
|
|
using Saxon.Api;
|
|
|
|
namespace ConsoleApplication1
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
XsltExecutable xsltExecutable;
|
|
var processor = new Processor(false);
|
|
|
|
string fileName = @"path\to\identity.xsl";
|
|
|
|
Uri stylesheetUri;
|
|
if (!Uri.TryCreate(fileName, UriKind.RelativeOrAbsolute, out stylesheetUri))
|
|
throw new ArgumentException(string.Format("Could not create an URI from stylesheet path '{0}'.", fileName), "fileName");
|
|
using (var stylesheet = File.OpenRead(fileName))
|
|
{
|
|
var compiler = processor.NewXsltCompiler();
|
|
compiler.BaseUri = stylesheetUri; //required to resolve stylesheet includes
|
|
xsltExecutable = compiler.Compile(stylesheet);
|
|
}
|
|
|
|
using (var sourceReader = File.OpenRead(fileName))
|
|
{
|
|
var transformer = xsltExecutable.Load();
|
|
var builder = processor.NewDocumentBuilder();
|
|
transformer.SetInputStream(sourceReader, stylesheetUri);
|
|
|
|
var result = new XDocument();
|
|
using (var output = result.CreateWriter())
|
|
{
|
|
var destination = new TextWriterDestination(output) { CloseAfterUse = true };
|
|
//var destination = new NullDestination();
|
|
|
|
//this one throws a NullReferenceException in saxon9he.dll!net.sf.saxon.Controller.openResult() + 0x224 bytes
|
|
//using the NullDestination instead works just fine
|
|
transformer.Run(destination);
|
|
|
|
}
|
|
Console.WriteLine(result);
|
|
}
|
|
}
|
|
}
|
|
}
|