# File lib/xtemplate/node.rb, line 221
    def prepare(xmlns = nil, enable = nil, templates = nil)
      # find xmlns:xxx="..."
      enable ||= DEFAULT_COMMAND
      templates ||= {}
      tmp = []
      @attrs.each_with_index{|elem,idx|
        attr,val, = elem
        if( (attr =~ /^xmlns:(.+)/) && (val == BIND_URI) )
          xmlns = $1
          @attrs.delete_at(idx)
          break
        end
      }

      if( @name )
        if( xmlns )
          if( @name =~ /#{xmlns}:(.+)/ )
            # special tags
            cmd = $1.tr('-','_').intern
            if( enable[cmd] )
              case cmd
              when :template
                t_name = attrval("name") || attrval("#{xmlns}:name")
                @name = nil
                @attrs = []
                if( t_name )
                  templates[t_name] = self
                end
              when :expand
                @name = nil
                @data_path = attrval("id") || attrval("#{xmlns}:id")
                with_strip = attrval("strip") || attrval("#{xmlns}:strip")
                case with_strip
                when "yes"
                  @expand = :strip
                else
                  @expand = :normal
                end
              when :select, :value_of
                @name = nil
                @data_path   = attrval("id") || attrval("#{xmlns}:id")
                if( @propagation = attrval("propagation") || attrval("#{xmlns}:propagation") )
                  @propagation = (@propagation == "yes")
                end
              when :copy_of
                @name = nil
                @data_path = attrval("id") || attrval("#{xmlns}:id")
                with_tag   = attrval("with") || attrval("#{xmlns}:with") || ''
                if( @data_path )
                  @data_path = @data_path + "{dump(#{with_tag})}"
                end
                if( @propagation = attrval("propagation") || attrval("#{xmlns}:propagation") )
                  @propagation = (@propagation == "yes")
                end
              when :each
                @name = nil
                @data_path = attrval("id") || attrval("#{xmlns}:id")
                if( @data_path )
                  @data_path = @data_path + "{array()}"
                end
              when :element
                @exname = attrval("name") || attrval("#{xmlns}:name")
                @data_path   = attrval("id") || attrval("#{xmlns}:id")
                @name = nil
                @attrs = []
              when :attribute
                @name = nil
                @exattr = attrval("name") || attrval("#{xmlns}:name")
                @data_path   = attrval("id") || attrval("#{xmlns}:id")
              when :property, :invoke
                @name = nil
                @data_path = attrval("id") || attrval("#{xmlns}:id")
                @data_path += "."
                @data_path += attrval("name") || attrval("#{xmlns}:name") || attrval("method") || attrval("#{xmlns}:method")
                withval = attrval("with") || attrval("#{xmlns}:with") || ''
                if( withval )
                  @data_path += "(#{withval})"
                end
              when :import
                src = attrval("src") || attrval("#{xmlns}:src")
                @data_path = "{data(#{src})}"
                @name = nil
              when :include
                src = attrval("src") || attrval("#{xmlns}:src")
                case src
                when /^\$(.+)/
                  doc = eval(src)
                when /^file:\/\/(.+)/
                  doc = File.open($1){|file| file.read }
                when /^http:\/\/(.+)/
                  raise(NotImplementedError, "'#{src}' can not be included.")
                else
                  doc = File.open(src){|file| file.read }
                end
                parser = XMLParser.new()
                node = parser.parse(doc)
                node.prepare(xmlns, enable, templates)
                @name = nil
                add_child(node)
              else
                raise(NotImplementedError, "'#{cmd.tr("_","-").to_s}' is not supported.")
              end
              if( @alt = (attrval("alt") || attrval("#{xmlns}:id")) )
                @data_path += "{alt(#{@alt})}"
              end
            else
              raise(RuntimeError, "'#{cmd.tr("_","-").to_s}' is invalid.")
            end
          else
            # parse attribute with xmlns
            tmp = []
            attr_id   = "#{xmlns}:id"
            attr_type = "#{xmlns}:type"
            attr_each = "#{xmlns}:each"
            attr_alt  = "#{xmlns}:alt"
            @attrs.each{|attr,val|
              case attr
              when attr_id
                if( enable[:@id] )
                  @data_path = val
                else
                  raise(RuntimeError, "'#{attr}' is invalid.")
                end
              when attr_each
                if( enable[:@each] )
                  @data_path = val + "{array()}"
                else
                  raise(RuntimeError, "'#{attr}' is invalid.")
                end
              when attr_type
                if( enable[:@type] )
                  @option[:type] = val
                else
                  raise(RuntimeError, "'#{attr}' is invalid.")
                end
              when attr_alt
                @alt = val
              else
                tmp.push([attr,val])
              end
            }
            if( @alt )
              @data_path += "{alt(#{@alt})}"
            end
            @attrs = tmp
          end
        else # xmlns
          # parse attribute
          tmp = []
          @attrs.each{|attr,val|
            case attr
            when 'id'
              if( enable[:@id] )
                @data_path = val
              else
                tmp.push([attr,val])
              end
            when 'each'
              if( enable[:@each] )
                @data_path = @data_path + "{array()}"
              else
                tmp.push([attr,val])
              end
            else
              tmp.push([attr,val])
            end
          }
          @attrs = tmp
        end
      end
      @children.each{|child|
        if( child.is_a?(XNode) )
          child.prepare(xmlns, enable, templates)
        end
      }
    end