Volání Saxonu z .NETu

Příklad 11. Volání Saxonu z .NET – XSLT.cs

using System;
using System.Collections.Generic;
using System.Text;
using Saxon.Api;
using System.IO;

class XSLT
{
    static void Main(string[] args)
    {
        if (args.Length < 3)
        {
            Console.Out.WriteLine("Usage: XSLT <source.xml> <style.xsl> <output>");
            System.Environment.Exit(1);
        }

        // Create a Processor instance.
        Processor processor = new Processor();

        // Load the source document
        XdmNode input = processor.NewDocumentBuilder().Build(new Uri(args[0]));

        // Create a transformer for the stylesheet.
        XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(args[1])).Load();

        // Set the root node of the source document to be the initial context node
        transformer.InitialContextNode = input;

        // Create a serializer
        String outfile = args[2];
        Serializer serializer = new Serializer();
        serializer.SetOutputStream(new FileStream(outfile, FileMode.Create, FileAccess.Write));

        // Transform the source XML to System.out.
        transformer.Run(serializer);            
    }
}

Kompilace

csc /lib:lib /reference:saxon9he-api.dll XSLT.cs