# File lib/facets/more/rtals.rb, line 94
  def self.parse( xml )
    building = ''
    body = []

    xml.each do |elem|
      #p elem.class

      tag, mode = [], nil
      case elem
      when REXML::Element

        attributes, ruby_attributes = {}, {}
        elem.attributes.each { |k, v|
          if k =~ /^rtal:/i
            ruby_attributes[k.sub(/^rtal:/i,'')] = v
          else
            attributes[k] = v
          end
        }

        if ruby_attributes.empty?
          tag = add_tag( elem.name, parse( elem ), attributes )

        else
          if bd = ruby_attributes["content"]
            tag << "out << #{bd}.to_s"
          elsif bd = ruby_attributes["replace"]
            tag << "out << #{bd}.to_s"
            mode = :replace
          else
            tag << parse( elem )
          end

          if cond = ( ruby_attributes["if"] || ruby_attributes["condition"] )
            #mode = :replace
            tag = ([ "if #{cond}" ].concat( tag ) << "end")
          end

          if enum = ( ruby_attributes["each"] || ruby_attributes["repeat"] )
            loopf = "#{enum}.each do"
            if d = ruby_attributes["do"]
              loopf << " |#{d}|"
            end
            tag = ([ loopf ].concat( tag ) << "end")
          end

          unless mode == :replace  #unless attributes.empty? #
            tag = add_tag( elem.name, tag, attributes )
          end

        end

      else
        tag << "out << #{elem.to_s.inspect}"

      end

      body.concat tag
    end

    building << body.flatten.join("\n")
    return building
  end