'Upgrade markup to comply with XHTML 1.1 where possible'

def upshift_markup(self):

    from calibre.ebooks.oeb.base import XPath, XML
    for x in self.oeb.spine:
        root = x.data
        if ((not root.get(XML('lang'))) and root.get('lang')):
            root.set(XML('lang'), root.get('lang'))
        body = XPath('//h:body')(root)
        if body:
            body = body[0]
        if (not hasattr(body, 'xpath')):
            continue
        for u in XPath('//h:u')(root):
            u.tag = 'span'
        (seen_ids, seen_names) = (set(), set())
        for x in XPath('//*[@id    or    @name]')(root):
            (eid, name) = (x.get('id', None), x.get('name', None))
            if eid:
                if (eid in seen_ids):
                    del x.attrib['id']
                else:
                    seen_ids.add(eid)
            if name:
                if (name in seen_names):
                    del x.attrib['name']
                else:
                    seen_names.add(name)
