'generate attributes declaration XML'

def getAttributesDeclarationXML(self):

    allAttributesXML = []
    if (len(self) > 0):
        for (attClass, atts) in self.iteritems():
            key_mode = (lambda att: att['mode'])
            atts_sorted_by_mode = sorted(atts.values(), key=key_mode, reverse=True)
            for (mode, atts) in itertools.groupby(atts_sorted_by_mode, key_mode):
                attributesXML = etree.Element('attributes')
                attributesXML.set('class', attClass)
                attributesXML.set('mode', mode)
                for att in sorted(atts, key=(lambda att: att['id'])):
                    attributeXML = etree.SubElement(attributesXML, 'attribute')
                    attributeXML.set('id', str(att['id']))
                    attributeXML.set('title', att['title'])
                    attributeXML.set('type', att['type'])
                    if att['defaultValue']:
                        etree.SubElement(attributeXML, 'default').text = att['defaultValue']
                allAttributesXML.append(attributesXML)
    return allAttributesXML
