'Return string of namespace attributes from this element and
ancestors.'

def _getNSattrs(self):

    attrs = ''
    context = self.context
    L = []
    while context:
        if hasattr(context, '_ns_prefix_uri'):
            for (prefix, uri) in context._ns_prefix_uri.items():
                if (prefix in L):
                    continue
                L.append(prefix)
                if prefix:
                    declname = ('xmlns:' + prefix)
                else:
                    declname = 'xmlns'
                if attrs:
                    attrs = ("%s\n                %s='%s'" % (attrs, declname, uri))
                else:
                    attrs = ("    %s='%s'" % (declname, uri))
        context = context.parentNode
    return attrs
