class Nokogiri::CSS::XPathVisitor

def visit_attribute_condition node

def visit_attribute_condition node
  attribute = if (node.value.first.type == :FUNCTION) or (node.value.first.value.first =~ /::/)
                ''
              else
                '@'
              end
  attribute += node.value.first.accept(self)
  # non-standard. attributes starting with '@'
  attribute.gsub!(/^@@/, '@')
  return attribute unless node.value.length == 3
  value = node.value.last
  value = "'#{value}'" if value !~ /^['"]/
  # quoted values - see test_attribute_value_with_quotes in test/css/test_parser.rb
  if (value[0]==value[-1]) && %q{"'}.include?(value[0])
    str_value = value[1..-2]
    if str_value.include?(value[0])
      value = 'concat("' + str_value.split('"', -1).join(%q{",'"',"}) + '","")'
    end
  end
  case node.value[1]
  when :equal
    attribute + "=" + "#{value}"
  when :not_equal
    attribute + "!=" + "#{value}"
  when :substring_match
    "contains(#{attribute},#{value})"
  when :prefix_match
    "starts-with(#{attribute},#{value})"
  when :dash_match
    "#{attribute}=#{value} or starts-with(#{attribute},concat(#{value},'-'))"
  when :includes
    value = value[1..-2] # strip quotes
    css_class(attribute, value)
  when :suffix_match
    "substring(#{attribute},string-length(#{attribute})-string-length(#{value})+1,string-length(#{value}))=#{value}"
  else
    attribute + " #{node.value[1]} " + "#{value}"
  end
end