(Going back on-list: please try to keep the thread intact, so everything is in the archives).
 
I'm not really clear exactly where your difficulties lie.
 
Your ExtensionFunctionDefinition can return net.sf.saxon.type.SequenceType.SINGLE_NODE for both the argument type and the return type.
 
When ExtensionFunctionCall.call() is called, the first argument will be an iterator; you can call next() on this iterator and the result will be a NodeInfo representing the node that was passed (in this case, a document node). If you need to serialize this node into lexical XML, the simplest way is to use the static method net.sf.saxon.query.QueryResult.serialize(node).
 
Your extension function needs to return an iterator that wraps a NodeInfo; so if your web service returns lexical XML you will need to parse this which you can do using context.getConfiguration().build(Source). You can wrap this in an iterator using net.sf.saxon.om.SingleNodeIterator(node). You can evaluate XPath expressions against the node using the methods in package net.sf.saxon.sxpath.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Full Midnight [mailto:full.midnight@gmail.com]
Sent: 07 February 2010 22:48
To: Michael Kay
Subject: Re: [saxon] Saxon 9.2 Java Integrated Extension functions: using XMLnodes as Input/Output

Good evening Dr. Kay and thank you for your response!

Sorry for my late reply, I was not at home these days.

Indeed, transforming XML nodes is the job of XSLT.

The thing is that this extension function would basically take as input some XML data (which can be passed as an argument to the extension function) and then call an web-service for further processing. In this case, the XML input data is the actual SOAP message. 
The web-service will then build a reply consisting of (other) XML data which needs to be somehow returned by the extension function.

Then the questions would be: how to provide the actual SOAP message string (which is the content of the "myvar" below) to the extension function? And then, will I be able to use XPath on the content returned by the web-service? I didn"t manage to find an answer to this up to this moment..


<variable name="myvar" type="xml">
      .... <!-- SOAP Message -->
</variable>
...
<eval expr="prefix:function($myvar)"/>

Thank you for your help!


On Thu, Feb 4, 2010 at 3:32 AM, Michael Kay <mike@saxonica.com> wrote:
Firstly, I would say that transforming XML nodes into other XML nodes is easier to do in XSLT than in Java (which you would expect, really, because XSLT is designed explicitly for that job).
 
Secondly, Saxon's XML nodes are in general immutable. By default the tree for your xsl:variable will use the TinyTree model, which you can't modify in-situ. Some tree models can be modified, but it probably isn't a good idea to do this because extension functions with side effects can behave unpredictably.
 
Using document() is appropriate where the input to your extension is a string or URI, but not where it is a node.
 
You don't actually say what you want your extension function to do, which makes it difficult to give you design advice.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Full Midnight [mailto:full.midnight@gmail.com]
Sent: 02 February 2010 18:03
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Saxon 9.2 Java Integrated Extension functions: using XMLnodes as Input/Output

Hi,

I'm dealing with a dilemma ..about how to implement an XSLT integrated extension function which takes as input an XML node and returns a (different) XML node for further processing.
I am not an expert in XSLT / Saxon processing, so please correct me if I'm wrong in any way..

Reading in Dr. Kay's book "XSLT 2.0 and XPath 2.0" (in the section regarding Extension functions), it seems that doing such a thing "might be easier using the document() approach". 
I am not familiar with this approach, so as a "side question" I would like to ask if using that approach I have both possibilities (i.e. passing an XML node to the "extension" and, after some processing of the input, returning another XML node for further processing).

Basically the input XML file which is going to be processed by the transformer will look like this:

=== input XML
<variable name="myvar" type="xml">
   <data>
      ....
   </data>
</variable>
...
<eval expr="prefix:function($myvar)"/>
=== input XML

.. when the prefix:function($myvar) will be called, I would like to have the entire XML node  visible above named "variable" (and in the exact format as in the input XML) available for further processing in the $myvar. After processing this input XML node provided as an argument to the extension function (processing which cannot be done anywhere but inside a java component), the extension function will return an output XML node which will be then used in the transformation ( by the way.. does the transformer knows how to handle this "dynamic" scenario when additional nodes are inserted in the input XML?).

Can you please tell me how one achieves such a thing using extension functions? If there is any other way for achieving this with Saxon 9.2, I would be glad to know about it..
If there are any places where such an implementation is done, please name it and I will look into it for further details.

Thank you in advance for your help,
M.