diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 5eb1e5a9..f86a87e6 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -671,7 +671,7 @@ def sort(array_of_nodes, order)
if order == :forward
index
else
- -index
+ index.map(&:-@)
end
end
ordered.collect do |_index, node|
diff --git a/test/xpath/test_base.rb b/test/xpath/test_base.rb
index 1dacd69d..53264a9e 100644
--- a/test/xpath/test_base.rb
+++ b/test/xpath/test_base.rb
@@ -416,6 +416,12 @@ def test_preceding
assert_equal( 4, cs.length )
end
+ def test_preceding_sibling
+ d = REXML::Document.new("")
+ matches = REXML::XPath.match(d, "a/b/x/preceding-sibling::node()")
+ assert_equal(["e", "d", "c"], matches.map(&:name))
+ end
+
def test_following
d = Document.new ""
start = XPath.first( d, "/a/b[@id='0']" )