func (s Stanza) TransformElement() element.Element { attrs := []element.Attr{} if s.To != "" { attrs = append(attrs, element.Attr{Key: "to", Value: s.To}) } if s.From != "" { attrs = append(attrs, element.Attr{Key: "from", Value: s.From}) } if s.ID != "" { attrs = append(attrs, element.Attr{Key: "id", Value: s.ID}) } if s.Type != "" { attrs = append(attrs, element.Attr{Key: "type", Value: s.Type}) } if s.Lang != "" { attrs = append(attrs, element.Attr{Key: "lang", Space: "xml", Value: s.Lang}) } if s.Namespaces != nil { for alias, ns := range s.Namespaces { // Handle top level namespace if alias == "" { attrs = append(attrs, element.Attr{Key: "xmlns", Value: ns}) continue } attrs = append(attrs, element.Attr{Key: alias, Space: "xmlns", Value: ns}) } } el := element.Element{Tag: s.Tag, Space: s.Space, Attr: attrs} if s.Data != "" { el = el.SetText(s.Data) } for _, child := range s.Children { el.Child = append(el.Child, child) } return el }