class REXML::Parsers::XPathParser

def expand(path_or_parsed)

def expand(path_or_parsed)
  if path_or_parsed.kind_of?(String)
    parsed = parse(path_or_parsed)
  else
    parsed = path_or_parsed
  end
  path = ""
  document = false
  while parsed.size > 0
    op = parsed.shift
    case op
    when :node
      path << "node()"
    when :attribute, :child, :following, :following_sibling,
          :ancestor, :ancestor_or_self, :descendant, :descendant_or_self,
          :namespace, :preceding, :preceding_sibling, :self, :parent
      path << "/" unless path.size == 0
      path << op.to_s.tr("_", "-")
      path << "::"
    when :any
      path << "*"
    when :qname
      prefix = parsed.shift
      name = parsed.shift
      path << prefix+":" if prefix.size > 0
      path << name
    when :predicate
      path << '['
      path << predicate_to_path( parsed.shift ) { |x| expand(x) }
      path << ']'
    when :document
      document = true
    else
      path << "UNKNOWN("
      path << op.inspect
      path << ")"
    end
  end
  path = "/"+path if document
  path
end