class Nokogiri::CSS::XPathVisitor
def visit_function node
def visit_function node # note that nth-child and nth-last-child are preprocessed in css/node.rb. msg = :"visit_function_#{node.value.first.gsub(/[(]/, '')}" return self.send(msg, node) if self.respond_to?(msg) case node.value.first when /^text\(/ 'child::text()' when /^self\(/ "self::#{node.value[1]}" when /^eq\(/ "position() = #{node.value[1]}" when /^(nth|nth-of-type|nth-child)\(/ if node.value[1].is_a?(Nokogiri::CSS::Node) and node.value[1].type == :AN_PLUS_B an_plus_b(node.value[1]) else "position() = #{node.value[1]}" end when /^(nth-last-child|nth-last-of-type)\(/ if node.value[1].is_a?(Nokogiri::CSS::Node) and node.value[1].type == :AN_PLUS_B an_plus_b(node.value[1], :last => true) else index = node.value[1].to_i - 1 index == 0 ? "position() = last()" : "position() = last() - #{index}" end when /^(first|first-of-type)\(/ "position() = 1" when /^(last|last-of-type)\(/ "position() = last()" when /^contains\(/ "contains(., #{node.value[1]})" when /^gt\(/ "position() > #{node.value[1]}" when /^only-child\(/ "last() = 1" when /^comment\(/ "comment()" when /^has\(/ node.value[1].accept(self) else args = ['.'] + node.value[1..-1] "#{node.value.first}#{args.join(', ')})" end end