Hello,

Thursday, April 04, 2002, 4:44:21 PM, Joseph Kesselman/CAM/Lotus wrote:

>>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?

JK> Every DOM node has a specific owner document, since we may need to use
JK> document-wide contextual information (such as the table of unique IDs).

That's what I expected.

JK> Note that, as in the DOM, ownership is independent of whether the node is
JK> actually part of the main document tree.

Oh, I didn't knew that, thank you!

JK> Since you're creating and returning DOM nodes, you have to follow that
JK> rule. We don't promise to process broken DOMs sucessfully.

Yes.. and I think I am following that rule. Here's my complete
function:

01:public static NodeSet cluster
02:  ( ExpressionContext i_ExprCtxt, NodeList i_NodeList, int i_iCount ) {
03:  NodeSet nsClusters = new NodeSet();
04:
05:  if ( i_NodeList != null && i_iCount>0) {
06:    int iSize = i_NodeList.getLength();
07:
08:    for ( int i=0; i<iSize; i+=i_iCount ) {
09:      ElementImpl cluster = new ElementImpl(null, i/i_iCount, "cluster");
10:
11:      int iMin = (iSize<i+i_iCount) ? iSize : i+i_iCount;
12:      for ( int j=i; j<iMin; j++ ) {
13:        ElementImpl item = new ElementImpl( cluster, j-i, "item");
14:        item.appendChild(i_NodeList.item(j));
15:        cluster.appendChild(item);
16:      }
17:      nsClusters.addNode(cluster);
18:      cluster=null;
19:    }
20:  }
21:
22:  return nsClusters;
23:}

As you can see, the elements in the list (and also the one used in the
XPath expression
>>> 5:   <xsl:variable name="var2" select="id($node/@attrID)/someChild" />
) are _not_ constructed/created, they're simple appended as children
of another parent. This has of course some side effects: The children
doesn't know its new parent - but this causes no problem. Also, the
function is working when called in line 2 (as written in my first
posting). Thus, I think that Xalan is behaving a little bit strange
here - even if I know that my function is a little bit strange too ;-)

JK> (Generally, this means it's safer to use the DOM's Document.createElementNS
JK> factory method, rather than trying to instantiate your ElementImpl
JK> directly.)

Yes. But, in my example, is it possible to create the "cluster" and
"items" elements (lines 09 and 13) by using Document.createElementNS
of the owner document of some of the passed nodes?

JK> As to whether this is exposing a bug in Xalan: I haven't analysed this
JK> deeply enough to have an opinion yet.

Perhaps we can clarify this ;-)


Best regards,
 Jens

Reply via email to