I certainly wouldn't use an extension function for this kind of problem, especially not in XSLT 2.0 where it's very easily solved within the language. I think you got a solution to this in a separate question on the xsl-list.
 
It is possible to write extensions functions that construct nodes "out of the blue" and return them to Saxon. However, every node that Saxon handles has a certain amount of overhead and red-tape associated with it, because of the rules needed to determine node identity, base URIs, document order, and so on. There are Saxon extension functions that work this way - the original saxon:tokenize() in 6.5.3 was an example - and they tend to work by creating a whole document. You can look at examples of how to do this in the source code for net.sf.saxon.functions.Extensions (or com.icl.saxon.functions.Extensions in 6.5.3). It basically involves creating a Builder and feeding SAX events to it.
 
But here, as I say (a) it's not necessary to use Java extensions at all, and (b) even if you do want to, it's best to make them work in terms of atomic values rather than nodes.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Namrata Patel
Sent: 15 March 2005 15:02
To: saxon-help@lists.sourceforge.net
Subject: [saxon] NodeInfo

Dear Michael,

 

            Thanks for your quick response regards to my “NodeInfo” thread. I kind of understand your answer, but it still is not clear as to how would I solve my problem. May be describing my problem to you might help. Here it goes…..

 

            In my input xml for my transformation, my data looks like this:

 

<ip v="10.0.1.4">

<ports>21,22</ports>

<results>c,l</results>

</ip>

 

            I want to flatten the ports and results for that ip, i.e. my output xml file should look something like this:

 

            <ip v=”10.0.1.4”>

                        <portresult p=”21” r=”c”/>

                        <portresult p=”22” r=”l”/>

            </ip>

 

            As you can see, I just want to get the first value of port and associate with the first value of result and so on. I have an extension function in java, that takes my node ports and results, constructs list of portresults for me and I just do xsl:copy-of and dump that result tree in my output xml. It was working fine before, but once I switched to Saxon, it is broken. 

 

            I really hope that there is a workaround for this problem and I can’t thank you enough for all your help.

 

Thx,

Namrata