From 5808ffa7a4a96a1dd75847203822f144cd5a5699 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sat, 12 Jul 2014 00:18:32 +0200 Subject: [PATCH] Updated XPath evaluator for the new AST. This is still a bit of a hack. Then again, it already was a hack to begin with. --- lib/oga/xpath/evaluator.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index a637a68..3c83dfe 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -45,23 +45,23 @@ module Oga end end - def on_absolute(node) + def on_absolute_path(node) if @document.respond_to?(:root_node) @context = XML::NodeSet.new([@document.root_node]) end - process_all(node.children) + on_path(node) end def on_path(node) - test, children = *node + last_index = node.children.length - 1 - process(test) + node.children.each_with_index do |test, index| + process(test) - if children and !@stack.empty? - swap_context - - process(children) + if index < last_index and !@stack.empty? + swap_context + end end end