public Item evaluateItem(XPathContext context) throws XPathException {
if (isSingleton && isAtomic) {
// optimize for this case
Item item = select.evaluateItem(context);
if (item == null) {
if (noNodeIfEmpty) {
return null;
} else {
return StringValue.EMPTY_STRING;
}
}
if (item instanceof StringValue) {
return item;
} else {
return ((AtomicValue)item).convert(BuiltInAtomicType.STRING, true, context).asAtomic();
}
}
SequenceIterator iter = select.iterate(context);
if (!isAtomic) {
iter = Atomizer.getAtomizingIterator(iter);
}
FastStringBuffer sb = new FastStringBuffer(1024);
boolean first = true;
String sep = " ";
while (true) {
Item item = iter.next();
if (item==null) {
break;
}
if (!first) {
sb.append(sep);
}
first = false;
sb.append(item.getStringValueCS());
}
if (first && noNodeIfEmpty) {
return null;
}
return StringValue.makeStringValue(sb.condense());