Re: How to get xsl:output/@method after transformation?

Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]> Sat, 1 May 2021 15:52:11 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
Yes, I've looked at this in more detail, and it seems that when the decision between XML/XHTML/HTML serialization is delayed until the first element tag is output, the only way you can intercept this is by subclassing the SerializerFactory and nominating your subclass using Configuration.setSerializerFactory(). If you override the method 

public Receiver getReceiver(Result result,
                            SerializationProperties params,
                            PipelineConfiguration pipe)
the first call will be with params that don't include a method. This call will therefore allocate an UncommittedSerializer. When the UncommittedSerializer gets a startElement() event it calls the SerializerFactory a second time, and on this occasion the params will include the selected method.

Michael Kay
Saxonica

> On 30 Apr 2021, at 19:53, John Ulric <[email protected]> wrote:
> 
> Thank you all for your answers. For what I'm trying to do, this simple one does the job:
> 
> xsltExecutable.getUnderlyingCompiledStylesheet().getPrimarySerializationProperties().getProperty("method")
> 
> The generic approach would be better, so I've also tried overriding Serializer like this:
> 
> class OutputMethodInterceptingSerializer extends Serializer {
> 
>     String method;
> 
>     OutputMethodInterceptingSerializer(final Processor processor, final OutputStream stream) {
>         super(processor);
>         this.setOutputStream(stream);
>     }
> 
>     @Override
>     public Receiver getReceiver(final PipelineConfiguration pipe, final SerializationProperties params) throws SaxonApiException {
>         method = params.getProperty("method");
>         return super.getReceiver(pipe, params);
>     }
> 
>     String getMethod() {
>         return method;
>     }
> 
> }
> 
> This, however, does not work for me: After the transformation, .getMethod() returns "html" for a stylesheet with an explicit <xsl:output method="html"/>. But for a stylesheet with no xsl:output element and (correct) auto-detection of html serialization, .getMethod() returns null. .getReceiver() gets called once both times, params is empty when auto-detection is in effect.
> 
> Any ideas?
> 
> John
> 
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help