def num_tags(tree, tag):
    """Returns the total number of tags in the tree of name tag

    Example, count planets: num_tags(tree, 'planet')

    :param tree: lxml etree
    :param tag: string containing <tag> name.
    :returns: integer representing number of tags found.
    """
    return int(tree.xpath("count(.//" + tag + ")"))