@@ -156,7 +156,7 @@ def match(path_stack, node)
156156 result = expr ( path_stack , nodeset )
157157 case result
158158 when Array # nodeset
159- result . uniq
159+ XPathParser . sort ( result )
160160 else
161161 [ result ]
162162 end
@@ -199,7 +199,7 @@ def expr( path_stack, nodeset, context=nil )
199199 nodeset = [ nodeset . first . root_node ]
200200 when :self
201201 nodeset = step ( path_stack ) do
202- [ :iterate_nodesets , [ nodeset ] ]
202+ [ :iterate_nodesets , [ XPathParser . sort ( nodeset ) ] ]
203203 end
204204 when :child
205205 nodeset = step ( path_stack ) do
@@ -323,7 +323,7 @@ def expr( path_stack, nodeset, context=nil )
323323 # If result is a nodeset, apply following predicates
324324 path_stack . unshift ( :node )
325325 nodeset = step ( path_stack ) do
326- [ :iterate_nodesets , [ result ] ]
326+ [ :iterate_nodesets , [ XPathParser . sort ( result ) ] ]
327327 end
328328 else
329329 return result
@@ -621,7 +621,7 @@ def step(path_stack, any_type: :element)
621621 nodes << node
622622 end
623623 end
624- new_nodeset = sort ( nodes . to_a )
624+ new_nodeset = nodes . to_a
625625 ensure
626626 leave ( :step , path_stack , new_nodeset ) if @debug
627627 end
@@ -761,7 +761,7 @@ def leave(tag, *args)
761761 # in and out of function calls. If I knew what the index of the nodes was,
762762 # I wouldn't have to do this. Maybe add a document IDX for each node?
763763 # Problems with mutable documents. Or, rewrite everything.
764- def sort ( array_of_nodes )
764+ def self . sort ( array_of_nodes )
765765 return array_of_nodes if array_of_nodes . size <= 1
766766
767767 new_arry = [ ]
0 commit comments