private Collection filterByCondition(Collection source, int from, int to) throws XPatherException {
        ArrayList result = new ArrayList();
        Iterator iterator = source.iterator();
        int index = 0;
        int size = source.size();
        while (iterator.hasNext()) {
            Object curr = iterator.next();
            index++;

            ArrayList logicValueList = new ArrayList(evaluateAgainst(singleton(curr), from, to, false, index, size, true, singleton(curr)));
            if (logicValueList.size() >= 1) {
                Object first = logicValueList.get(0);
                if (first instanceof Boolean) {
                    if ( ((Boolean)first).booleanValue() ) {
                        result.add(curr);
                    }
                } else if (first instanceof Integer) {
                    if ( ((Integer)first).intValue() == index ) {
                        result.add(curr);
                    }
                } else {
                    result.add(curr);
                }
            }
        }
        return result;
    }