'Return the number of siblings before or after child or raise ValueError if child has no parent.'

def sibling_count(self, child, before=True, same_type=False):

    parent = child.getparent()
    if (parent is None):
        raise ValueError(u'Child    has    no    parent')
    if same_type:
        siblings = OrderedSet(child.itersiblings(preceding=before))
        return len((self.element_map[self.map_tag_name(child.tag)] & siblings))
    else:
        if before:
            return parent.index(child)
        return ((len(parent) - parent.index(child)) - 1)
