Support for the ancestor-or-self axis.
This commit is contained in:
parent
e0544959ee
commit
d09ab26680
|
@ -72,14 +72,16 @@ module Oga
|
||||||
def on_axis(node, context)
|
def on_axis(node, context)
|
||||||
name, test = *node
|
name, test = *node
|
||||||
|
|
||||||
return send("on_axis_#{name}", test, context)
|
handler = name.gsub('-', '_')
|
||||||
|
|
||||||
|
return send("on_axis_#{handler}", test, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_axis_ancestor(node, context)
|
def on_axis_ancestor(node, context)
|
||||||
nodes = XML::NodeSet.new
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
context.each do |xml_node|
|
context.each do |xml_node|
|
||||||
while xml_node.respond_to?(:parent) and xml_node.parent
|
while has_parent?(xml_node)
|
||||||
xml_node = xml_node.parent
|
xml_node = xml_node.parent
|
||||||
|
|
||||||
if node_matches?(xml_node, node)
|
if node_matches?(xml_node, node)
|
||||||
|
@ -92,6 +94,23 @@ module Oga
|
||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_axis_ancestor_or_self(node, context)
|
||||||
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
|
context.each do |xml_node|
|
||||||
|
while has_parent?(xml_node)
|
||||||
|
if node_matches?(xml_node, node)
|
||||||
|
nodes << xml_node
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
xml_node = xml_node.parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nodes
|
||||||
|
end
|
||||||
|
|
||||||
def child_nodes(nodes)
|
def child_nodes(nodes)
|
||||||
children = XML::NodeSet.new
|
children = XML::NodeSet.new
|
||||||
|
|
||||||
|
@ -121,6 +140,10 @@ module Oga
|
||||||
|
|
||||||
return name_matches && ns_matches
|
return name_matches && ns_matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_parent?(node)
|
||||||
|
return node.respond_to?(:parent) && !!node.parent
|
||||||
|
end
|
||||||
end # Evaluator
|
end # Evaluator
|
||||||
end # XPath
|
end # XPath
|
||||||
end # Oga
|
end # Oga
|
||||||
|
|
Loading…
Reference in New Issue