Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add feature that the ':only-child' pseudo class should work even though it's in ':not' pseudo class. #858

merged 1 commit into from

2 participants


cite: 6.6.7. The negation pseudo-class in specification

The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument.

Also contain a :only-child pseudo class.



Nokogiri::CSS.xpath_for '*:not(:only-child)' # => ["//*[not(only-child(.))]"] 

merged this commit:

Nokogiri::CSS.xpath_for '*:not(:only-child)' # => ["//*[not(last() = 1)]"]
@leejarvis leejarvis merged commit d1b0afd into sparklemotion:master

1 check failed

Details default The Travis build could not complete due to an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @ykzts

    Add feature that the ':only-child' pseudo class should work even thou…

    ykzts authored
    …gh it's in ':not' pseudo class.
This page is out of date. Refresh to see the latest.
1  lib/nokogiri/css/xpath_visitor.rb
@@ -109,6 +109,7 @@ def visit_pseudo_class node
when "last", "last-child" then "position() = last()"
when "first-of-type" then "position() = 1"
when "last-of-type" then "position() = last()"
+ when "only-child" then "last() = 1"
when "only-of-type" then "last() = 1"
when "empty" then "not(node())"
when "parent" then "node()"
5 test/css/test_xpath_visitor.rb
@@ -17,6 +17,11 @@ def test_not_last_child
@parser.parse('ol > *:not(:last-child)'))
+ def test_not_only_child
+ assert_xpath('//ol/*[not(last() = 1)]',
+ @parser.parse('ol > *:not(:only-child)'))
+ end
def test_function_calls_allow_at_params
assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
Something went wrong with that request. Please try again.