Basic support for the preceding-sibling xpath axis

This commit is contained in:
Yorick Peterse committed 2014-08-05 19:28:26 +02:00
1 parent e34a1ed481
commit 8a9b26fa73
2 files changed
+60

No files matched your search

+27
View File
@@ -354,6 +354,33 @@ module Oga
return nodes
end
##
# Evaluates the `preceding-sibling` axis.
#
# @param [Oga::XPath::Node] ast_node
# @param [Oga::XML::NodeSet] context
# @return [Oga::XML::NodeSet]
#
def on_axis_preceding_sibling(ast_node, context)
nodes = XML::NodeSet.new
context.each do |context_node|
check = true
parent = has_parent?(context_node) ? context_node.parent : nil
@document.each_node do |doc_node|
# Test everything *until* we hit the current context node.
if doc_node == context_node
break
elsif doc_node.parent == parent and node_matches?(doc_node, ast_node)
nodes << doc_node
end
end
end
return nodes
end
##
# Returns a node set containing all the child nodes of the given set of
# nodes.