You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Martin Rusnak <ma...@cyberspace.sk> on 2006/02/06 17:37:20 UTC

Implementing aggregation of multiple XSLT results

Hello all,

I would like to use xalan to implement aggregated XML pipeline similar to the
Cocoon pipeline aggregator. The final document shall be an HTML page composed
of 2 or more XML fragments which are results of an XSLT transformations.
The problem is, that each XSLT transformer produces startDocument and
endDocument SAX events, so that they occur many times in the final document.
According to SAX API, it is allowed to call startDocument/endDocument only
once. So, how to solve this problem?

Diagram showing the pipeline configuration:

                                           +------------+
                                      +----| XSLT Trf 1 |<- SAX Evts
+------------------------+  SAX Evts |    +------------+
| Aggregated Content Trf |<----------+
+------------------------+           |    +------------+
                                      +----| XSLT Trf 2 |<- SAX Evts
                                           +------------+

Simplified code:

TransformerHandler serializerHandler = factory.newTransformerHandler();
serializerHandler.setResult(new StreamResult(out));

TransformerHandler xslHandler1 = factory.newTransformerHandler(templates1);
TransformerHandler xslHandler2 = factory.newTransformerHandler(templates2);

xslHandler1.setResult(new SAXResult(serializerHandler));
xslHandler2.setResult(new SAXResult(serializerHandler));

serializerHandler.startDocument();
serializerHandler.startElement("", "html", "html", HTML_ATTRS);
// other initial elements

xslHandler1.startDocument();
// Generate SAX events for the first fragment
xslHandler1.endDocument();

xslHandler2.startDocument();
// Generate SAX events for the second fragment
xslHandler2.endDocument();

serializerHandler.endElement("", "html", "html");
serializerHandler.endDocument();


Martin