import logging


def get_type(node):
    """Get xpath-node's type.(recursive function).
    Args:
        node: The xpath-node's root.
    Returns:
        return xpath-node's type.
    """
    if node.keyword not in ['leaf','leaf-list']:
        return None
    type_stmt = node.search_one("type")
    if not type_stmt:
        logging.info("leaf %s has no type defination", node.arg)
        return None
    type_spec = type_stmt.i_type_spec
    if not type_spec:
        return None
    if type_spec.name == "leafref":
        if hasattr(type_spec, "i_target_node"):
            target_node = type_spec.i_target_node
            return get_type(target_node)
        else:
            return None
    else:
        return type_stmt.i_type_spec.name