Would it make more sense to invert the two checks? I.e. first check that type_attr is nil and then check for node.attributes['type']?