diff --git a/Tests/CssSelectorTest.php b/Tests/CssSelectorTest.php
index 50daeccd1d27819f4edff05235c489cd5f344926..9fbdf1d09f522bac6478f56758e5f7b437750c15 100644
--- a/Tests/CssSelectorTest.php
+++ b/Tests/CssSelectorTest.php
@@ -47,7 +47,7 @@ class CssSelectorTest extends \PHPUnit_Framework_TestCase
             array('h1', "h1"),
             array('foo|h1', "foo:h1"),
             array('h1, h2, h3', "h1 | h2 | h3"),
-            array('h1:nth-child(3n+1)', "*/*[name() = 'h1' and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
+            array('h1:nth-child(3n+1)', "*/*[(name() = 'h1') and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
             array('h1 > p', "h1/p"),
             array('h1#foo', "h1[@id = 'foo']"),
             array('h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
diff --git a/Tests/XPath/TranslatorTest.php b/Tests/XPath/TranslatorTest.php
index 30f7189f06f18ba248e02af0515a12b0dbd99b6e..9759d185e0bcf784bf1aa9f78f48eb168d708c9e 100644
--- a/Tests/XPath/TranslatorTest.php
+++ b/Tests/XPath/TranslatorTest.php
@@ -101,18 +101,20 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
             array('e[foo^="bar"]', "e[@foo and starts-with(@foo, 'bar')]"),
             array('e[foo$="bar"]', "e[@foo and substring(@foo, string-length(@foo)-2) = 'bar']"),
             array('e[foo*="bar"]', "e[@foo and contains(@foo, 'bar')]"),
+            array('e[foo!="bar"]', "e[not(@foo) or @foo != 'bar']"),
+            array('e[foo!="bar"][foo!="baz"]', "e[(not(@foo) or @foo != 'bar') and (not(@foo) or @foo != 'baz')]"),
             array('e[hreflang|="en"]', "e[@hreflang and (@hreflang = 'en' or starts-with(@hreflang, 'en-'))]"),
-            array('e:nth-child(1)', "*/*[name() = 'e' and (position() = 1)]"),
-            array('e:nth-last-child(1)', "*/*[name() = 'e' and (position() = last() - 0)]"),
-            array('e:nth-last-child(2n+2)', "*/*[name() = 'e' and (last() - position() - 1 >= 0 and (last() - position() - 1) mod 2 = 0)]"),
+            array('e:nth-child(1)', "*/*[(name() = 'e') and (position() = 1)]"),
+            array('e:nth-last-child(1)', "*/*[(name() = 'e') and (position() = last() - 0)]"),
+            array('e:nth-last-child(2n+2)', "*/*[(name() = 'e') and (last() - position() - 1 >= 0 and (last() - position() - 1) mod 2 = 0)]"),
             array('e:nth-of-type(1)', "*/e[position() = 1]"),
             array('e:nth-last-of-type(1)', "*/e[position() = last() - 0]"),
             array('div e:nth-last-of-type(1) .aclass', "div/descendant-or-self::*/e[position() = last() - 0]/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' aclass ')]"),
-            array('e:first-child', "*/*[name() = 'e' and (position() = 1)]"),
-            array('e:last-child', "*/*[name() = 'e' and (position() = last())]"),
+            array('e:first-child', "*/*[(name() = 'e') and (position() = 1)]"),
+            array('e:last-child', "*/*[(name() = 'e') and (position() = last())]"),
             array('e:first-of-type', "*/e[position() = 1]"),
             array('e:last-of-type', "*/e[position() = last()]"),
-            array('e:only-child', "*/*[name() = 'e' and (last() = 1)]"),
+            array('e:only-child', "*/*[(name() = 'e') and (last() = 1)]"),
             array('e:only-of-type', "e[last() = 1]"),
             array('e:empty', "e[not(*) and not(string-length())]"),
             array('e:EmPTY', "e[not(*) and not(string-length())]"),
@@ -126,7 +128,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
             array('e:nOT(*)', "e[0]"),
             array('e f', "e/descendant-or-self::*/f"),
             array('e > f', "e/f"),
-            array('e + f', "e/following-sibling::*[name() = 'f' and (position() = 1)]"),
+            array('e + f', "e/following-sibling::*[(name() = 'f') and (position() = 1)]"),
             array('e ~ f', "e/following-sibling::f"),
             array('div#container p', "div[@id = 'container']/descendant-or-self::*/p"),
         );
diff --git a/XPath/XPathExpr.php b/XPath/XPathExpr.php
index c7ef97cb9a12e9879bd72ca931995efe4d16a6ad..3434cc847d4ab7ae795c7c052991e7e1a2c35de6 100644
--- a/XPath/XPathExpr.php
+++ b/XPath/XPathExpr.php
@@ -68,7 +68,7 @@ class XPathExpr
      */
     public function addCondition($condition)
     {
-        $this->condition = $this->condition ? sprintf('%s and (%s)', $this->condition, $condition) : $condition;
+        $this->condition = $this->condition ? sprintf('(%s) and (%s)', $this->condition, $condition) : $condition;
 
         return $this;
     }