def findall_deep(node, selector, ns, depth=0, maxDepth=-1):
    """
    recursively find all nodes matching the xpath selector

    :param node: the input etree node
    :param selector: the xpath selector
    :param ns: a dict of namespaces
    :param depth: the current depth
    :param maxDepth: the maximum number of levels to navigate
    :return: a list of matching nodes
    """
    results = node.findall(selector, ns) if ns else node.findall(selector)
    if maxDepth == -1 or (depth < maxDepth):
        children = list(node)
        if children and len(children) > 0:
            for child in children:
                results = results + findall_deep(child, selector, ns, depth+1, maxDepth)
    return results