Evan Lenz wrote:
>
> I'm using Xalan 2.1.0.
>
> Is there a way to override the xsl:output method declared in the stylesheet?
> In particular, is it possible to avoid the default HTML serialization of
> result trees that have an "html" root element? I found that even if I
> explicitly call setOutputProperty(OutputKeys.METHOD, "xml"), my request is
> disregarded if the resulting root element ends up being "html".
>
> My assessment is as follows:
>
> 1. setOutputProperties overrides xsl:output (per JAXP documentation)
> 2. Xalan's automatic HTML-detection overrides setOutputProperties (!)
> 3. but HTML-detection does *not* override xsl:output (per XSLT spec)
>
> Is this assessment correct?
This is -not- how things should be working. The SerializerSwitcher is
set up to honor your explicit method request and not substitute the HTML
serializer in that case even if the tests for automatic HTML
serialization are otherwise met. Can I see the code where you're
calling setOutputProperty? Send it to me off the list if it's
sensitive. Ideally, if you could send the XML, XSLT, and Java code in a
small demonstration example of the problem, it would be easier for me to
recreate it.
>
> Effectively, this means that the only place I can have true control over the
> serialization method is with xsl:output. I need control from the API.
Agreed.
>
> One of the nice things about TransformerFactory.newTransformer() is that it
> provides a simple way to serialize documents (simply copying Source to
> Result). If I have no way of ensuring that well-formed XML will be
> serialized, I can no longer use this as a general purpose serializer.
Well, it should work, as I stated.
>
> Finally, is there a way to determine (perhaps not through JAXP) what a
> particular output property is for a transformation before it's serialized?
> This implies breaking the atomicity of Transformer.transform(). The reason
> for this is that in certain cases I might want to go with the default output
> method and still somehow know how I should call, for example,
> ServletHttpResponse.setContentType(...)
Hmmmm. I need to think about this. I don't think there's any way of
easily getting this at the moment. I suppose you could create your own
serializers for XML and HTML by extending the Xalan-provided ones.
Then, you'd specify your serializers in the output_xml.properties and
output_html.properties files. You'd override the startDocument() method
to report which serializer was being used and invoke
super.startDocument(). The other methods would just come from the
parent class.
This seems to me to be something that servlet writers might want to do.
What do people think of adding a
xalan:report-properties-used="class-name" attribute on the xsl:output
element that would call a method in a new interface, passing the current
output properties? I'm not sure how this would work for additional
serializers used to handle redirected output and stuff but I'd like to
see what everyone thinks first.
Gary
>
> Any help on these issues would be greatly appreciated.
>
> Evan Lenz
> XYZFind Corp.