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)
  # Support non-standard css
  attribute.gsub!(/^@@/, '@')
  return attribute unless node.value.length == 3
  value = node.value.last
  value = "'#{value}'" if value !~ /^['"]/
  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
    "contains(concat(\" \", #{attribute}, \" \"),concat(\" \", #{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