Hello,
I've got a small problem with xsl:variable and user extensions.
The error message is:
context does not have an owner document!
[org.apache.xml.utils.WrappedRuntimeException: context does not have an owner
document!]
Here's the snippet causing this error message:
--------------8X--------------8X--------------8X--------------
1: <xsl:variable name="node" select="." />
2: <xsl:variable name="var1" select="id($node/@attrID)/someChild" />
3: <xsl:variable name="clusters" select="utils:cluster(node/someChildren,5)"/>
4: <xsl:for-each select="$cluster">
5: <xsl:variable name="var2" select="id($node/@attrID)/someChild" />
6: ...
7: </xsl:for-each>
--------------8X--------------8X--------------8X--------------
As you can see I've written an extension "cluster", this function
groups a list into clusters, each cluster has 5 items of the original
list. Here's a snippet of this (Java) function:
--------------8X--------------8X--------------8X--------------
1: public static NodeSet cluster
2: ( ExpressionContext i_ExprCtxt, NodeList i_NodeList, int i_iCount ) {
3: NodeSet nsClusters = new NodeSet();
4: for ( int i=0; i<i_NodeList.getLength(); i+=i_iCount ) {
5: ElementImpl cluster =
6: new ElementImpl(null /* Document */, i/i_iCount, "cluster");
7: .. add children to cluster element ...
8: }
9: return nsClusters;
10: }
--------------8X--------------8X--------------8X--------------
The error message above rises in the line of the XSLT when defining
the xsl variable "var2" (line 5). You'll notice that the definitions of xsl
variable "var1" (line 2) is identical to "var2" - but only "var2" causes the
error.
I suppose that my extension causes the trouble: By constructing a new
Element (of my own implementation), the context of the "var2"
definition is inside an element with no document.
I'm not sure how to solve the problem. Of course, my work-around is
by using a "var1" definition - but this doesn't solves the real
problem. This leads me to two questions:
1) Is my implementation of the extension functions buggy, because is
it e.g. forbidden to construct (and indirectly return) an element with no
owner document? Is it possible to use the original owner document (so
the element is linked to the document (line 6), but the element is descendant
of the document)?
2) Is it a bug in Xalan, because I expect "var2" to be working if
"var1" is working? The context of this expression is IMHO $node, not
the elements in the for-each loop.
Best regards,
Jens
P.S.: The error is at last caused by the id-function. The same
construct not using the id function (e.g. var2=someX/someChild instead
of id(@attrID)/someChild) is working.