def passageLoop(parent, new_tree, xpath1, xpath2=None, preceding_siblings=False, following_siblings=False):
    """ Loop over passages to construct and increment new tree given a parent and XPaths

    :param parent: Parent on which to perform xpath
    :param new_tree: Parent on which to add nodes
    :param xpath1: List of xpath elements
    :type xpath1: [str]
    :param xpath2: List of xpath elements
    :type xpath2: [str]
    :param preceding_siblings: Append preceding siblings of XPath 1/2 match to the tree
    :param following_siblings: Append following siblings of XPath 1/2 match to the tree
    :return: Newly incremented tree
    """
    current_1, queue_1 = __formatXpath__(xpath1)
    if xpath2 is None:  # In case we need what is following or preceding our node
        result_1, loop = performXpath(parent, current_1)
        if loop is True:
            queue_1 = xpath1

        central = None
        has_no_queue = len(queue_1) == 0
        # For each sibling, when we need them in the context of a range
        if preceding_siblings or following_siblings:
            for sibling in xmliter(parent):
                if sibling == result_1:
                    central = True
                    # We copy the node we looked for (Result_1)
                    child = copyNode(result_1, children=has_no_queue, parent=new_tree)
                    # if we don't have children
                    # we loop over the passage child
                    if not has_no_queue:
                        passageLoop(
                            result_1,
                            child,
                            queue_1,
                            None,
                            preceding_siblings=preceding_siblings,
                            following_siblings=following_siblings
                        )
                    # If we were waiting for preceding_siblings, we break it off
                    # As we don't need to go further
                    if preceding_siblings:
                        break
                elif not central and preceding_siblings:
                    copyNode(sibling, parent=new_tree, children=True)
                elif central and following_siblings:
                    copyNode(sibling, parent=new_tree, children=True)
    else:
        result_1, loop = performXpath(parent, current_1)
        if loop is True:
            queue_1 = xpath1
            if xpath2 == xpath1:
                current_2, queue_2 = current_1, queue_1
            else:
                current_2, queue_2 = __formatXpath__(xpath2)
        else:
            current_2, queue_2 = __formatXpath__(xpath2)

        if xpath1 != xpath2:
            result_2, loop = performXpath(parent, current_2)
            if loop is True:
                queue_2 = xpath2
        else:
            result_2 = result_1

        if result_1 == result_2:
            has_no_queue = len(queue_1) == 0
            child = copyNode(result_1, children=has_no_queue, parent=new_tree)
            if not has_no_queue:
                passageLoop(
                    result_1,
                    child,
                    queue_1,
                    queue_2
                )
        else:
            start = False
            # For each sibling
            for sibling in xmliter(parent):
                # If we have found start
                # We copy the node because we are between start and end
                if start:
                    # If we are at the end
                    # We break the copy
                    if sibling == result_2:
                        break
                    else:
                        copyNode(sibling, parent=new_tree, children=True)
                # If this is start
                # Then we copy it and initiate star
                elif sibling == result_1:
                    start = True
                    has_no_queue_1 = len(queue_1) == 0
                    node = copyNode(sibling, children=has_no_queue_1, parent=new_tree)
                    if not has_no_queue_1:
                        passageLoop(sibling, node, queue_1, None, following_siblings=True)

            continue_loop = len(queue_2) == 0
            node = copyNode(result_2, children=continue_loop, parent=new_tree)
            if not continue_loop:
                passageLoop(result_2, node, queue_2, None, preceding_siblings=True)

    return new_tree
def passageLoop ( parent , new_tree , xpath1 , xpath2 = None , preceding_siblings = False , following_siblings = False ) : current_1 , queue_1 = __formatXpath__ ( xpath1 ) if xpath2 is None : result_1 , loop = performXpath ( parent , current_1 ) if loop is True : queue_1 = xpath1 central = None has_no_queue = len ( queue_1 ) == 0 if preceding_siblings or following_siblings : for sibling in xmliter ( parent ) : if sibling == result_1 : central = True child = copyNode ( result_1 , children = has_no_queue , parent = new_tree ) if not has_no_queue : passageLoop ( result_1 , child , queue_1 , None , preceding_siblings = preceding_siblings , following_siblings = following_siblings ) if preceding_siblings : break elif not central and preceding_siblings : copyNode ( sibling , parent = new_tree , children = True ) elif central and following_siblings : copyNode ( sibling , parent = new_tree , children = True ) else : result_1 , loop = performXpath ( parent , current_1 ) if loop is True : queue_1 = xpath1 if xpath2 == xpath1 : current_2 , queue_2 = current_1 , queue_1 else : current_2 , queue_2 = __formatXpath__ ( xpath2 ) else : current_2 , queue_2 = __formatXpath__ ( xpath2 ) if xpath1 != xpath2 : result_2 , loop = performXpath ( parent , current_2 ) if loop is True : queue_2 = xpath2 else : result_2 = result_1 if result_1 == result_2 : has_no_queue = len ( queue_1 ) == 0 child = copyNode ( result_1 , children = has_no_queue , parent = new_tree ) if not has_no_queue : passageLoop ( result_1 , child , queue_1 , queue_2 ) else : start = False for sibling in xmliter ( parent ) : if start : if sibling == result_2 : break else : copyNode ( sibling , parent = new_tree , children = True ) elif sibling == result_1 : start = True has_no_queue_1 = len ( queue_1 ) == 0 node = copyNode ( sibling , children = has_no_queue_1 , parent = new_tree ) if not has_no_queue_1 : passageLoop ( sibling , node , queue_1 , None , following_siblings = True ) continue_loop = len ( queue_2 ) == 0 node = copyNode ( result_2 , children = continue_loop , parent = new_tree ) if not continue_loop : passageLoop ( result_2 , node , queue_2 , None , preceding_siblings = True ) return new_tree
Loop over passages to construct and increment new tree given a parent and XPaths

    :param parent: Parent on which to perform xpath
    :param new_tree: Parent on which to add nodes
    :param xpath1: List of xpath elements
    :type xpath1: [str]
    :param xpath2: List of xpath elements
    :type xpath2: [str]
    :param preceding_siblings: Append preceding siblings of XPath 1/2 match to the tree
    :param following_siblings: Append following siblings of XPath 1/2 match to the tree
    :return: Newly incremented tree