Project

Profile

Help

Extend XMLEmitter

Added by Anonymous over 18 years ago

Legacy ID: #3842111 Legacy Poster: Jeje (mrjeje64)

Hello everyone, I have to apply special processing during transformation. My main requirement is that I can not modify the XSL file to do so. So I was wondering if I could extend XMLEmitter and so intercept all receiver events to add some text. However this cause me the following problem : how can I tell Saxon to use my specialized class instead of using the XMLEmitter one. So I looked into the SerializerFactory class and modified it to use my specialized class. My question : wouldn't it be interesting for Saxon to natively enable developers to use their own emitters instead of saxon's predefined ones ? Of course I could create my receiver/emitter pipeline outside Saxon and call the transform method with these decorated objects. However, in this case, I would have to process information in the xsl:output myself instead of relying on Saxon which does this natively. So I do not want to have to do this. Or maybe there is a way to do this with Saxon but did not find it ??? Regards, Jérôme.


Replies (1)

RE: Extend XMLEmitter - Added by Anonymous over 18 years ago

Legacy ID: #3842915 Legacy Poster: Michael Kay (mhkay)

You can write your own Emitter and nominate it to be used as the transformation result, either by naming it in the method attribute of xsl:output (see http://www.saxonica.com/documentation/extensions/output-extras/method.html), or by supplying it as the second argument of the Transformer.transform() method (Emitter implements javax.xml.transform.Result). You might find the programming a bit easier, and the code more portable, if you write it as a SAX ContentHandler rather than as a Saxon Emitter. This will avoid the need to access Saxon internals such as the NamePool. However, you're right to observe that if you supply an Emitter, Receiver, or SAXResult directly to the transform() method, then you don't get things like indentation added to the serialization pipeline, whether xsl:output requests them or not. This is also true if you supply it to the xsl:output method attribute (the logic is in source module SerializerFactory. The only way I can see round this is for you to duplicate the logic of SerializerFactory.getReceiver in your own code.

    (1-1/1)

    Please register to reply