0
votes

What I am trying to achieve is (using Saxon-B 9.1):

1) Run XSLT transformation with object of below Example class as parameter

2) Object's properties are populated using reflexive extension function with selected Nodes

3) Run second XSLT transformation (on different XML input) and pass the above object with populated values as parameter

4) Insert XML nodes from the object into output document

My class is below:

public class Example {
.   private NodeSet test;

.   public RequestInfo() {}

.   public void settest(NodeList t) {
.       this.test = t;
.   }
.   public NodeList gettest() {
.       return test;
.   }
}

First transformation seems to populate my object fine (using settest() method within XSLT) - I can see correct nodes added to the NodeList.

However, I am getting below error when running 2nd transformation and calling gettest() method from within XSLT:

NodeInfo returned by extension function was created with an incompatible Configuration

I was thinking should I not use NodeList but maybe some different, equivalent type that would be recognised by Saxon? I tried it with NodeSet but got same error message.

Any help on this would be appreciated.

1

1 Answers

1
votes

You haven't shown enough information to see exactly what you are doing wrong, but I can try and explain the error message. Saxon achieves its fast performance in part by allocating integer codes to all the names used in your XML documents and stylesheets, and using integer comparisons to compare names. The place where the mapping of integers to names is held is the NamePool, and the NamePool is owned by the Saxon Configuration object; so all documents, stylesheets, etc participating in a transformation must be created under the same Configuration (it's a bit like the DOM rule that all Nodes must be created under the Document they are attached to). The message means that you've got at least two different Configuration objects around. A Configuration gets created either explicitly by your application, or implicitly when you create a TransformerFactory, an XPathFactory, or other such objects.

I wonder whether this mixing of XSLT and Java code is really a good idea? Often when I see it, the Java code is being used because people haven't mastered how to achieve the desired effect in XSLT. There are many good reasons for NOT using the DOM with Saxon: it's very slow, it requires more lines of code, it's not thread-safe, it's harder to debug, ...