// Evaluate the "use" expression against this context node
SequenceIterator useval = use.iterate(xc);
while (true) {
AtomicValue item = (AtomicValue)useval.next();
if (item == null) {
break;
}
int actualItemType = item.getItemType().getPrimitiveType();
if (!Type.isComparable(actualItemType, soughtItemType)) {
// if the types aren't comparable, simply ignore this key value
break;
}
Object val;
if (soughtItemType==Type.UNTYPED_ATOMIC) {
// if the supplied key value is untyped atomic, we build an index using the
// actual type returned by the use expression
if (collation==null) {
val = item.getStringValue();
} else {
val = collation.getCollationKey(item.getStringValue());
}
} else if (soughtItemType==Type.STRING) {
// if the supplied key value is a string, there is no match unless the use expression
// returns a string or an untyped atomic value
if (collation==null) {
val = item.getStringValue();
} else {
val = collation.getCollationKey(item.getStringValue());
}
} else {
// Ignore NaN values
if (item instanceof NumericValue && ((NumericValue)item).isNaN()) {
break;
}
try {
val = item.convert(soughtItemType, xc);
} catch (XPathException err) {
// ignore values that can't be converted to the required type
break;
}
}