* @return
*/
public Element filter(Element e,Node node) throws NoSuchFunctionException, NoSuchAxisException {
if (node.getTagName().equals("*")||node.getTagName().equals(e.nodeName())){
if (node.getPredicate()!=null){
Predicate p = node.getPredicate();
if (p.getOpEm()==null){
if (p.getValue().matches("\\d+")&&getElIndex(e)==Integer.parseInt(p.getValue())){
return e;
}else if (p.getValue().endsWith("()")&&(Boolean)callFilterFunc(p.getValue().substring(0,p.getValue().length()-2),e)){
return e;
}
//todo p.value ~= contains(./@href,'renren.com')
}else {
if (p.getLeft().matches("[^/]+\\(\\)")){
Object filterRes=p.getOpEm().excute(callFilterFunc(p.getLeft().substring(0,p.getLeft().length()-2),e).toString(),p.getRight());
if (filterRes instanceof Boolean && (Boolean) filterRes){
return e;
}else if(filterRes instanceof Integer && e.siblingIndex()==Integer.parseInt(filterRes.toString())){
return e;
}
}else if (p.getLeft().startsWith("@")){
String lValue = e.attr(p.getLeft().substring(1));
Object filterRes = p.getOpEm().excute(lValue,p.getRight());
if ((Boolean) filterRes){
return e;
}
}else {
// 操作符左边不是函数、属性默认就是xpath表达式了
List<Element> eltmp = new LinkedList<Element>();
eltmp.add(e);
List<Object> rstmp=evaluate(p.getLeft(),new Elements(eltmp));
if ((Boolean) p.getOpEm().excute(StringUtils.join(rstmp,""),p.getRight())){
return e;
}
}
}
}else {