code: protected static Iterable<Node> evaluate(Node element, XPathExpression expression,
          boolean detatch) throws XPathExpressionException {
          final NodeList nodeList = (NodeList) expression.evaluate(element, XPathConstants.NODESET);
          return new Iterable<Node>() {
  
              @Override
              public Iterator<Node> iterator() {
                  return new Iterator<Node>() {
  
                      int index = 0;
  
                      @Override
                      public boolean hasNext() {
                          return index < nodeList.getLength();
                      }
  
                      @Override
                      public Node next() {
                          Node item = nodeList.item(index);
                          if (detatch) {
                              // detaching the node from its parent dramatically improves performance
                              // for xpath!
                              item.getParentNode().removeChild(item);
                          }
                          index++;
                          return item;
                      }
                  };
              }
          };
      }
docs: evaluates a XPath expression and loops over the nodeset result
  
  @param element
  @param xpath
  @return
  @throws XPathExpressionException