public short filterNode(int testNode)
{
boolean foundKey = false;
Vector keys = m_keyDeclarations;
QName name = m_name;
KeyIterator ki = (KeyIterator)(((XNodeSet)m_keysNodes).getContainedIter());
org.apache.xpath.XPathContext xctxt = ki.getXPathContext();
if(null == xctxt)
assertion(false, "xctxt can not be null here!");
try
{
XMLString lookupKey = m_ref;
// 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;
// xctxt.setNamespaceContext(ki.getPrefixResolver());
// Query from the node, according the the select pattern in the
// use attribute in xsl:key.
XObject xuse = kd.getUse().execute(xctxt, testNode, ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET)
{
XMLString exprResult = xuse.xstr();
if (lookupKey.equals(exprResult))
return DTMIterator.FILTER_ACCEPT;
}
else
{
DTMIterator nl = ((XNodeSet)xuse).iterRaw();
int useNode;
while (DTM.NULL != (useNode = nl.nextNode()))
{
DTM dtm = getDTM(useNode);
XMLString exprResult = dtm.getStringValue(useNode);
if ((null != exprResult) && lookupKey.equals(exprResult))
return DTMIterator.FILTER_ACCEPT;
}
}
} // end for(int i = 0; i < nDeclarations; i++)
}
catch (javax.xml.transform.TransformerException te)
{
throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
if (!foundKey)
throw new RuntimeException(
XSLMessages.createMessage(
XSLTErrorResources.ER_NO_XSLKEY_DECLARATION,
new Object[] { name.getLocalName()}));
return DTMIterator.FILTER_REJECT;
}