at.setValue(atVal);
}
int p = 0;
for (final Iterator<String> it = groupedSequence.iterate(); it.hasNext(); ) {
final GroupedValueSequence currentGroup = groupedSequence.get(it.next());
context.proceed(this);
// set binding variable to current group
var.setValue(currentGroup);
var.checkType();
//set value of grouping keys for the current group
for (int i=0; i< groupKeyVar.length ; i ++) {
groupKeyVar[i].setValue(currentGroup.getGroupKey().itemAt(i).toSequence());
}
if (positionalVariable != null) {
final ValueSequence ps = new ValueSequence();
for (int i = 0; i < currentGroup.getItemCount(); i++) {
ps.add(new IntegerValue(p + i + 1));
}
at.setValue(ps);
}
//evaluate real return expression
final Sequence val = groupReturnExpr.eval(null);
resultSequence.addAll(val);
p += currentGroup.getItemCount();
}
//Reset the context position
context.setContextSequencePosition(0, null);
context.popLocalVariables(mark);
}