using Saxon.Api;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ResultDocDocTypeMissing
{
class Program
{
static void Main(string[] args)
{
Processor proc = new Processor(false);
string xslt = "testTest
Result test {.}Result {.}
";
using (StringReader sr = new StringReader(xslt))
{
XsltTransformer transformer = proc.NewXsltCompiler().Compile(sr).Load();
transformer.InitialTemplate = new QName("http://www.w3.org/1999/XSL/Transform", "initial-template");
transformer.Run(proc.NewSerializer(Console.Out));
Console.WriteLine();
MyResultDocumentHandler resDocHandler = new MyResultDocumentHandler(proc);
transformer.ResultDocumentHandler = resDocHandler;
transformer.Run(proc.NewSerializer(Console.Out));
foreach (MySerializer ser in resDocHandler.Serializers)
{
Console.WriteLine("{0}:\n{1}", ser.Href, ser.Result);
Console.WriteLine();
}
}
}
}
internal class MyResultDocumentHandler : IResultDocumentHandler
{
private Processor proc;
public List Serializers { get; set; }
public MyResultDocumentHandler(Processor proc)
{
this.proc = proc;
Serializers = new List();
}
public XmlDestination HandleResultDocument(string href, Uri baseUri)
{
var ser = new MySerializer(proc, href);
Serializers.Add(ser);
return ser;
}
}
internal class MySerializer : Serializer
{
private StringWriter resultWriter;
public string Result { get; private set; }
public string Href { get; }
public MySerializer(Processor processor, string href)
{
SetProcessor(processor);
Href = href;
resultWriter = new StringWriter();
SetOutputWriter(resultWriter);
}
public override void Close()
{
Result = resultWriter.ToString();
resultWriter.Close();
resultWriter.Dispose();
base.Close();
}
}
}