From 211caf00c6362fb748d9984d2d04eff9e6e06a31 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 4 Aug 2014 18:57:21 +0200 Subject: [PATCH] Proper support for the XPath "following" axis. --- lib/oga/xpath/evaluator.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index e97c3fa..1621199 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -252,15 +252,22 @@ module Oga nodes = XML::NodeSet.new context.each do |context_node| - current = context_node + check = false - # TODO: implement me properly this time. - # - # Step 1: gather *all* the nodes that come after the current node, - # regardless of their nesting. - # - # Step 2: compare all those nodes with the given test, only return - # those that match. + @document.each_node do |doc_node| + # Skip child nodes of the current context node, compare all + # following nodes. + if doc_node == context_node + check = true + throw :skip_children + end + + next unless check + + if can_match_node?(doc_node) and node_matches?(doc_node, node) + nodes << doc_node + end + end end return nodes