Project

Profile

Help

NullReferenceException with Saxon 9.8.0.4 EE .NET with various ways trying to use saxon:next-in-chain

Added by Martin Honnen over 6 years ago

While exploring various ways to chain stylesheets with Saxon 9.8 I have run into problems with a NullReferenceException using @saxon:next-in-chain@ in a C# program with Saxon .Net 9.8.0.4 EE.

The reduced program I have that exhibits the problem both with a stylesheet using e.g. @<xsl:output saxon:next-in-chain="test201708180302.xsl"/>@ directly in a stylesheet being executed or with an attempt to set @serializer.SetOutputProperty(Serializer.NEXT_IN_CHAIN, nextUri);@ is as follows:


    class Program
    {
        static void Main(string[] args)
        {
            Processor processor = new Processor(true);

            Console.WriteLine("{0} {1}", processor.ProductTitle, processor.ProductVersion);

            Xslt30Transformer transformer = processor.NewXsltCompiler().Compile(new Uri(Path.GetFullPath(args[0]))).Load30();

            Serializer serializer = new Serializer();

            if (args.Length > 2)
            {
                string nextUri = new Uri(Path.GetFullPath(args[2])).AbsoluteUri;
                Console.WriteLine(nextUri);
                serializer.SetOutputProperty(Serializer.NEXT_IN_CHAIN, nextUri);
            }
            

            serializer.SetOutputWriter(Console.Out);

            using (FileStream fileStream = new FileStream(args[1], FileMode.Open))
            {
                transformer.ApplyTemplates(fileStream, serializer);
            }
                
        }
    }

When I run that passing in two arguments, the first being the stylesheet file name @test201708180304.xsl@ for the file and the second the file name for the input @test2017081803.xml@ where the stylesheet has the @saxon:next-in-chain@ I get the following stack trace

Unbehandelte Ausnahme: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei com.saxonica.serialize.SerializerFactoryPE.prepareNextStylesheet(PipelineConfiguration pipe, String href, String
baseURI, Result result)
   bei net.sf.saxon.lib.SerializerFactory.getReceiver(Result result, PipelineConfiguration pipe, Properties props, CharacterMapIndex charMapIndex)
   bei Saxon.Api.Serializer.GetReceiver(Configuration config)
   bei Saxon.Api.Xslt30Transformer.GetDestinationReceiver(XmlDestination destination)
   bei Saxon.Api.Xslt30Transformer.ApplyTemplates(Stream input, XmlDestination destination)
   bei SaxonChain1.Program.Main(String[] args) in c:\users\martin honnen\documents\visual studio 2017\Projects\SaxonChain1\SaxonChain1\Program.cs:Zeile 35.

Stylesheet is




    
    
    
    
    
    
        
        
    
    

the referenced stylesheet is




    
    
    
    
        
        
    
    

Any input XML suffices, e.g.




    test

Interestingly, when I pass in as the first argument a normal stylesheet (i.e. one not using @saxon:next-in-chain@) but add a third argument to set @serializer.SetOutputProperty(Serializer.NEXT_IN_CHAIN, nextUri);@ I get the same exception:

Unbehandelte Ausnahme: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei com.saxonica.serialize.SerializerFactoryPE.prepareNextStylesheet(PipelineConfiguration pipe, String href, String
baseURI, Result result)
   bei net.sf.saxon.lib.SerializerFactory.getReceiver(Result result, PipelineConfiguration pipe, Properties props, CharacterMapIndex charMapIndex)
   bei Saxon.Api.Serializer.GetReceiver(Configuration config)
   bei Saxon.Api.Xslt30Transformer.GetDestinationReceiver(XmlDestination destination)
   bei Saxon.Api.Xslt30Transformer.ApplyTemplates(Stream input, XmlDestination destination)
   bei SaxonChain1.Program.Main(String[] args) in c:\users\martin honnen\documents\visual studio 2017\Projects\SaxonChain1\SaxonChain1\Program.cs:Zeile 35.

Is there something wrong in the way I use the .NET API or is there a bug causing this exception?


Please register to reply