Vector keys = ki.getKeyDeclarations();
QName name = ki.getName();
try
{
XMLString lookupKey = m_lookupKey;
// System.out.println("lookupKey: "+lookupKey);
int nDeclarations = keys.size();
// Walk through each of the declarations made with xsl:key
for (int i = 0; i < nDeclarations; i++)
{
KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i);
// Only continue if the name on this key declaration
// matches the name on the iterator for this walker.
if(!kd.getName().equals(name))
continue;
foundKey = true;
ki.getXPathContext().setNamespaceContext(ki.getPrefixResolver());
// See if our node matches the given key declaration according to
// the match attribute on xsl:key.
double score = kd.getMatch().getMatchScore(ki.getXPathContext(),
testNode);
if (score == kd.getMatch().MATCH_SCORE_NONE)
continue;
// Query from the node, according the the select pattern in the
// use attribute in xsl:key.
XObject xuse = kd.getUse().execute(ki.getXPathContext(), testNode,
ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET)
{
XMLString exprResult = xuse.xstr();
((KeyIterator)m_lpi).addRefNode(exprResult, testNode);
if (lookupKey.equals(exprResult))
return DTMIterator.FILTER_ACCEPT;
}
else
{
DTMIterator nl = xuse.iter();
int useNode;
short result = -1;
/*
We are walking through all the nodes in this nodeset
rather than stopping when we find the one we're looking
for because we don't currently save the state of KeyWalker
such that the next time it gets called it would continue
to look in this nodeset for any further matches.
TODO: Try to save the state of KeyWalker, i.e. keep this node
iterator saved somewhere and finish walking through its nodes
the next time KeyWalker is called before we look for any new
matches. What if the next call is for the same match+use
combination??
*/
while (DTM.NULL != (useNode = nl.nextNode()))
{
DTM dtm = getDTM(useNode);
XMLString exprResult = dtm.getStringValue(useNode);
((KeyIterator)m_lpi).addRefNode(exprResult, testNode);
if ((null != exprResult) && lookupKey.equals(exprResult))
result = DTMIterator.FILTER_ACCEPT;
//return DTMIterator.FILTER_ACCEPT;