Support #4087
closedAny reason why setting up a ResultDocumentHandler on .NET on XsltTransformer would make the DOCTYPE for serialized HTML result documents be swallowed?
0%
Description
I am trying to use Saxon 9.8.0.15 HE on .NET to handle result documents produced by xsl:result-document
through an ResultDocumentHandler
set up on XsltTransformer
.
I have hit a problem where the transformation creating some HTML result documents writes out the HTML 5 <!DOCTYPE HTML>
when I don't use my ResultDocumentHandler
, however when I set it up the results I capture there lack the HTML 5 DOCTYPE
declaration.
I am not sure whether it is because of my wrong attempt to set up that handler or because due to a bug in Saxon.
Any advice appreciated.
Test case is
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 = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='3.0' expand-text='yes'><xsl:output method='html' indent='yes' html-version='5.0'/><xsl:template match='/' name='xsl:initial-template'><html><head><title>test</title></head><body><h1>Test</h1></body></html><xsl:for-each select='1 to 3'><xsl:result-document href='result-{.}.html'><html><head><title>Result test {.}</title></head><body><h1>Result {.}</h1></body></html></xsl:result-document></xsl:for-each></xsl:template></xsl:stylesheet>";
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<MySerializer> Serializers { get; set; }
public MyResultDocumentHandler(Processor proc)
{
this.proc = proc;
Serializers = new List<MySerializer>();
}
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();
}
}
}
A sample output file created from that transformation looks like
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Result test 1</title></head>
<body>
<h1>Result 1</h1>
</body>
</html>
however the output the handler writes to the console is
result-1.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Result test 1</title></head>
<body>
<h1>Result 1</h1>
</body>
</html>
without the DOCTYPE declaration
Files
Please register to edit this issue