String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if(argIsNodeSetDTM)
{
XNodeSet ns = (XNodeSet)arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if(len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM)
{
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode()))
{
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null)
{
continue; // We already have 'em.
}
else
{
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl =
kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref,
xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
}
else
{
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname,
ref,
xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}