# File lib/nokogiri/xml/node.rb, line 145
      def xpath *paths
        return NodeSet.new(document) unless document

        paths, handler, ns, binds = extract_params(paths)

        sets = paths.map { |path|
          ctx = XPathContext.new(self)
          ctx.register_namespaces(ns)
          path = path.gsub(/\/xmlns:/,'/:') unless Nokogiri.uses_libxml?

          binds.each do |key,value|
            ctx.register_variable key.to_s, value
          end if binds

          ctx.evaluate(path, handler)
        }
        return sets.first if sets.length == 1

        NodeSet.new(document) do |combined|
          sets.each do |set|
            set.each do |node|
              combined << node
            end
          end
        end
      end