def empty_like(root, basetype=None):
    """
    Creates an empty collection of nodes that mimic the structure
    found in root.

    :param root: Subtree to be duplicated.
    :param basetype: Type of nodes to create.
    :return: Empty structure that matches the structure of the
        template tree.
    """
    if basetype is None:
        basetype = type(root)
    top = basetype()
    for child in root.children:
        top.add_child(empty_like(child, basetype))
    return top