def fix_related_item_tag(dom):
    """
    Remove <mods:relatedItem> tag in case that there is only <mods:location>
    subtag.
    """
    location = dom.match(
        "mods:mods",
        "mods:relatedItem",
        "mods:location"
    )

    if not location:
        return
    location = first(location)

    location.replaceWith(
        dhtmlparser.HTMLElement()
    )

    # remove whole <mods:relatedItem> tag, if there is nothing else left in it
    related_item = dom.match(
        "mods:mods",
        "mods:relatedItem"
    )
    related_item = first(related_item)

    if not related_item.getContent().strip():
        related_item.replaceWith(dhtmlparser.HTMLElement())
def fix_related_item_tag ( dom ) : location = dom . match ( "mods:mods" , "mods:relatedItem" , "mods:location" ) if not location : return location = first ( location ) location . replaceWith ( dhtmlparser . HTMLElement ( ) ) related_item = dom . match ( "mods:mods" , "mods:relatedItem" ) related_item = first ( related_item ) if not related_item . getContent ( ) . strip ( ) : related_item . replaceWith ( dhtmlparser . HTMLElement ( ) )
Remove <mods:relatedItem> tag in case that there is only <mods:location>
    subtag.