context.put( index, new NodeVariable(String.valueOf(i)) );
}
// execute the loop body
BaseElementDef bodyDef = loopDef.getLoopBodyDef();
Variable loopResult = bodyDef != null ? new BodyProcessor(bodyDef).run(scraper, context) : new EmptyVariable();
debug(bodyDef, scraper, loopResult);
if (!isEmpty) {
resultList.addAll( loopResult.toList() );
}
}
// restores previous value of item variable
if (item != null && itemBeforeLoop != null) {
context.put(item, itemBeforeLoop);
}
// restores previous value of index variable
if (index != null && indexBeforeLoop != null) {
context.put(index, indexBeforeLoop);
}
}
return isEmpty ? new EmptyVariable() : new ListVariable(resultList);
}