def fix_location_tag(dom):
location = dom.match(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>)<EOL>if not location:<EOL><INDENT>return<EOL><DEDENT>location = first(location)<EOL>if not location.find("<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT>url = location.find("<STR_LIT>", {"<STR_LIT>": "<STR_LIT>"})<EOL>if url:<EOL><INDENT>url = first(url).getContent()<EOL><DEDENT>else:<EOL><INDENT>urls = filter(<EOL>lambda x: x.getContent(),<EOL>location.find("<STR_LIT>")<EOL>)<EOL>if not urls:<EOL><INDENT>return<EOL><DEDENT>url_tag = max(urls, key=lambda x: len(x.getContent()))<EOL>url = url_tag.getContent()<EOL><DEDENT>replacer = dhtmlparser.parseString("""<STR_LIT>""" + url + """<STR_LIT>""")<EOL>location.replaceWith(<EOL>first(replacer.find("<STR_LIT>"))<EOL>)<EOL>dhtmlparser.makeDoubleLinked(dom)<EOL>
Repair the <mods:location> tag (the XSLT template returns things related to
paper books, not electronic documents).