def author_affiliations(author, html_flag=True):
<EOL>convert = lambda xml_string: xml_to_html(html_flag, xml_string)<EOL>affilations = []<EOL>if author.get("<STR_LIT>"):<EOL><INDENT>for affiliation in author.get("<STR_LIT>"):<EOL><INDENT>affiliation_json = OrderedDict()<EOL>affiliation_json["<STR_LIT:name>"] = []<EOL>if affiliation.get("<STR_LIT>"):<EOL><INDENT>affiliation_json["<STR_LIT:name>"].append(convert(affiliation.get("<STR_LIT>")))<EOL><DEDENT>if affiliation.get("<STR_LIT>") and affiliation.get("<STR_LIT>").strip() != '<STR_LIT>':<EOL><INDENT>affiliation_json["<STR_LIT:name>"].append(convert(affiliation.get("<STR_LIT>")))<EOL><DEDENT>if affiliation_json["<STR_LIT:name>"] == []:<EOL><INDENT>del affiliation_json["<STR_LIT:name>"]<EOL><DEDENT>if ((affiliation.get("<STR_LIT>") and affiliation.get("<STR_LIT>").strip() != '<STR_LIT>')<EOL>or affiliation.get("<STR_LIT>") and affiliation.get("<STR_LIT>").strip() != '<STR_LIT>'):<EOL><INDENT>affiliation_address = OrderedDict()<EOL>affiliation_address["<STR_LIT>"] = []<EOL>affiliation_address["<STR_LIT>"] = OrderedDict()<EOL>if affiliation.get("<STR_LIT>") and affiliation.get("<STR_LIT>").strip() != '<STR_LIT>':<EOL><INDENT>affiliation_address["<STR_LIT>"].append(affiliation.get("<STR_LIT>"))<EOL>affiliation_address["<STR_LIT>"]["<STR_LIT>"] = []<EOL>affiliation_address["<STR_LIT>"]["<STR_LIT>"].append(affiliation.get("<STR_LIT>"))<EOL><DEDENT>if affiliation.get("<STR_LIT>") and affiliation.get("<STR_LIT>").strip() != '<STR_LIT>':<EOL><INDENT>affiliation_address["<STR_LIT>"].append(affiliation.get("<STR_LIT>"))<EOL>affiliation_address["<STR_LIT>"]["<STR_LIT>"] = affiliation.get("<STR_LIT>")<EOL><DEDENT>if affiliation_address != {}:<EOL><INDENT>affiliation_json["<STR_LIT:address>"] = affiliation_address<EOL><DEDENT><DEDENT>if affiliation_json != {}:<EOL><INDENT>affilations.append(affiliation_json)<EOL><DEDENT><DEDENT><DEDENT>if affilations != []:<EOL><INDENT>return affilations<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
compile author affiliations for json output