How to chain two stylesheets using streaming and Saxon EE 9.8 .Net in C# code?
Added by Martin Honnen over 7 years ago
Following the advice "run the two transformations directly from the API, feeding the output of one to be the input of the next. (XsltTransformer implements Destination, so you can directly supply one transformation as the destination of another" from https://saxonica.plan.io/boards/3/topics/6928 I have tried to write a C# program to chain two @XsltTransformer@ s. This seems to work fine if I don't use streaming in the stylesheets, however, when trying to use streaming the code emits a warning
Warning The unnamed mode is streamable, but the input is not supplied as a stream
after first outputting the diagnostic message
Streaming file:///C:/SomePath/input.xml
so it seems the chaining does not work in a pure streaming way, the second stylesheet does not seem to use streaming.
Is there a way with the .NET API to chain two stylesheets using streaming with both stylesheets?
Here is my attempt to chain the stylesheets in C#:
static void Main(string[] args)
{
Processor processor = new Processor(true);
processor.SetProperty("http://saxon.sf.net/feature/timing", "true");
processor.SetProperty("http://saxon.sf.net/feature/xsltSchemaAware", "true");
Console.WriteLine("{0} {1}", processor.ProductTitle, processor.ProductVersion);
XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(Path.GetFullPath(args[0]))).Load();
Uri inputUri = new Uri(Path.GetFullPath(args[1]));
XsltTransformer nextTransformer;
XdmDestination result = new XdmDestination();
if (args.Length > 2)
{
nextTransformer = processor.NewXsltCompiler().Compile(new Uri(Path.GetFullPath(args[2]))).Load();
nextTransformer.Destination = result;
using (FileStream fileStream = new FileStream(args[1], FileMode.Open))
{
transformer.SetInputStream(fileStream, inputUri);
transformer.Run(nextTransformer);
}
}
else
{
using (FileStream fileStream = new FileStream(args[1], FileMode.Open))
{
transformer.SetInputStream(fileStream, inputUri);
transformer.Run(result);
}
}
Console.WriteLine(result.XdmNode.OuterXml);
}
In the Java world I think I have managed to do it using @StreamingTransformerFactory@ and @newXMLFilter@, setting up one stylesheet as an XMLFilter for the other, but these APIs are not available in the .NET version.
As a side note, the above code needed the @processor.SetProperty("http://saxon.sf.net/feature/xsltSchemaAware", "true");@ to work at all with stylesheets using streaming, if I don't set that property then any attempt to chain two stylesheets using streaming fails with
Error The source document has been schema-validated, but the stylesheet is not schema-aware. A stylesheet is schema-aware if either (a) it contains an xsl:import-schema declaration, or (b) the stylesheet compiler was configured to be schema-aware. Unbehandelte Ausnahme: Saxon.Api.DynamicError: The source document has been schema-validated, but the stylesheet is not schema-aware. A stylesheet is schema-aware if either (a) it contains an xsl:import-schema declaration, or (b) the styles heet compiler was configured to be schema-aware. bei Saxon.Api.XsltTransformer.Close() bei Saxon.Api.XsltTransformer.Run(XmlDestination destination) bei SaxonChain1.Program.Main(String[] args) in c:\SomePath\visual studio 2017\Projects\SaxonChain1\SaxonChain1\Program.cs:Zeile 38.
although none of the stylesheets make any attempt to do schema-aware processing or validation.
Replies (3)
Please register to reply
RE: How to chain two stylesheets using streaming and Saxon EE 9.8 .Net in C# code? - Added by Michael Kay over 7 years ago
We've done some work recently to make sure this is possible on the Java platform, but it's possible that we still have some catching up to do on .NET. We'll look into it. We've got a bit of a backlog on .NET questions at the moment because O'Neil is on vacation.
RE: How to chain two stylesheets using streaming and Saxon EE 9.8 .Net in C# code? - Added by Martin Honnen about 7 years ago
Any info on this? As Saxon-C has seen a new release I suppose O'Neil is back from vacation, is he looking into open .NET issues too?
RE: How to chain two stylesheets using streaming and Saxon EE 9.8 .Net in C# code? - Added by Michael Kay about 7 years ago
We were hoping to get a new maintenance release out on Friday, after doing a triage on open issues to identify as many as possible that could be cleared before the release. We hit a couple of test failures that were sufficient to stop the release, which will hopefully be quickly resolved. I haven't checked the status of this particular issue.
Please register to reply