Thank you for your advice!
I should have probably said from the start that this is part of a framework; I am not trying to re-write XSLT, but in my case I really have to use these things to gain performance :-)

I searched through the web quite a bit and found other hints about TinyBuilder, so I have started to play with it.
So I have now something like this:

public NodeInfo combineNodes(List<NodeInfo> nodes) throws Exception {
        Builder docBuilder = new TinyBuilder();

        Configuration config = new Configuration();
        PipelineConfiguration pipelineConfiguration = config.makePipelineConfiguration();
       
        docBuilder.setPipelineConfiguration(pipelineConfiguration);
        docBuilder.open();
        docBuilder.startDocument(0);

        for (NodeInfo nodeInfo : nodes) {
            nodeInfo.copy(docBuilder, 0, 0);
        }

        docBuilder.endDocument();
        docBuilder.close();

        return docBuilder.getCurrentRoot();
}

.. and in the integrated extension function I use something like for returning the combined nodes to the transformation:

return SingleNodeIterator.makeIterator( combineNodes( selectedNodes ) );

Although no exception is thrown, I do not see any nodes being returned to the transformation (selectedNodes do contain valid XML nodes).
Any suggestions on what I should be further looking into?
Perhaps SingleNodeIterator is not what I should be using? Having more nodes to return.. perhaps NodeListIterator or ListIterator should be used?

The ext. func. result type is NODE_SEQUENCE:
   @Override
    public SequenceType getResultType(SequenceType[] args) {
        return SequenceType.NODE_SEQUENCE;
    }

Merry Christmas,
M.



On Thu, Dec 22, 2011 at 8:10 PM, Michael Kay <mike@saxonica.com> wrote:
As someone else (Andrew?) mentioned, it seems odd to be doing this in a Java extension function when it is much more easily done in XSLT.

To do this in Java, create an appropriate Builder (e.g. a TinyBuilder), and then use

NodeInfo.copy()

to copy each root node with this Builder as the Receiver. You probably should initialize the builder using open() and startDocument(), and then at the end close it down with endDocument() and close().

Michael Kay
Saxonica


On 21/12/2011 21:17, Full Midnight wrote:
Hi all,

I really did not yet found a solution on how to approach this problem, so I would kindly ask for your support.

There are several XML fragments, each of them being deserialized individually (as queries will run on each of them) using something like:
---
StreamSource source = new StreamSource(new ByteArrayInputStream( xmlFragment.getBytes( "UTF-8" ) ));
Configuration configuration = context.getConfiguration();
NodeInfo deserializedFragment = configuration.buildDocument(source);
---

At a later point in time, some of these fragments will have to be sent back to the transformation, through the integrated extension function.

My question is how can I build another NodeInfo which is composed using the (already deserialized) NodeInfos (corresponding to each XML fragment)?
Please note that, for performance reasons, I would like to avoid serializing each fragment from NodeInfo to XML and then deserializing the concatenated XML fragments to NodeInfo.



As an example, below we have two XML fragments:
--- Fragment 1
<fragment id="1">
  ...
</fragment id="1">
---

--- Fragment 2
<fragment id="2">
  ...
</fragment id="2">
---

In the integrated extension function, a new NodeInfo will be build by putting together nodeInfoFragment1 (the NodeInfo corresponding to Fragment 1) and nodeInfoFragment2 ((the NodeInfo corresponding to Fragment 2), so that the NodeInfo returned from the extension function to the transformation will be:
---
<fragment id="1">
  ...
</fragment id="1">
<fragment id="2">
  ...
</fragment id="2">
---

Any ideas / links on how this can be achieved?

Thank you in advance for your answers.

Regards,
M.


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help