The simplest method might be to create an instance of TinyBuilder and then send events to it:
This is a bit low-level, it requires you to allocate name codes from the NamePool. So you may prefer to front-end this with a ReceivingContentHandler so that you can write to the SAX interface:
TinyBuilder tb = new TinyBuilder();
PipelineConfiguration pipe = config.makePipelineConfiguration()
ReceivingContentHandler rch = new ReceivingContentHandler();
and then you can write SAX events to rch. On completion, pass tb.getCurrentNode() as the return value from your extension.
Note that any nodes you construct must be under the current Configuration used for the transformation or query. You can discover this by having an XPathContext argument to your extension function; the Configuration can be found from the XPathContext via the Controller.
Michael Kay

From: Christian Kullmann []
Sent: 05 March 2009 12:11
Subject: [saxon] Returning a Node or Tree from an XSLT Extension

Hi all,


I am currently trying to write an XSLT Extension that calls a Stored Procedure on an SQL Server and returning the Result Set as a tree to the calling xslt.

The basic functions on how to write an XSLT Extension and calling the Stored Procedure from within it, I have already implemented (might need a bit tweaking, but it works).


What I still am having trouble with is the mapping of the results into an XML structure that I can return to the calling XSLT.

I have been googling quite a bit through the net but have not found a suitable example where a set of nodes or tree is built from scratch.


Does anyone have a suitable example or can point me towards one?
Many thanks in advance


Best Regards




Christian Kullmann


Head of Support

Assentis Technologies AG

Blegistrasse 1, 6343 Rotkreuz, Switzerland


Web    :

Email  :

Mobile : +41-77-450 64 23

Phone  : +41-41-790 91 92


This e-mail, any associated files and the information contained in the e-mail might be confidential and are intended for the addressee(s) only. Any unauthorised use, disclosure, alteration or any other use of this message is prohibited and might be unlawful. Any views or opinions expressed in this e-mail are those of the sender and do not necessarily represent those of the company.

Neither Assentis Technologies nor the sender accept any responsibility for any kind of damage as the result of viruses or transmission problems.