aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rexml/xpath_parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rexml/xpath_parser.rb')
-rw-r--r--lib/rexml/xpath_parser.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 91b8ad48c8..98ed70cc10 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -76,6 +76,8 @@ module REXML
# Performs a depth-first (document order) XPath search, and returns the
# first match. This is the fastest, lightest way to return a single result.
+ #
+ # FIXME: This method is incomplete!
def first( path_stack, node )
#puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )"
return nil if path.size == 0
@@ -123,14 +125,6 @@ module REXML
r = expr( path_stack, nodeset )
#puts "MAIN EXPR => #{r.inspect}"
r
-
- #while ( path_stack.size > 0 and nodeset.size > 0 )
- # #puts "MATCH: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'"
- # nodeset = expr( path_stack, nodeset )
- # #puts "NODESET: #{nodeset.inspect}"
- # #puts "PATH_STACK: #{path_stack.inspect}"
- #end
- #nodeset
end
private
@@ -158,9 +152,10 @@ module REXML
#puts "IN QNAME"
prefix = path_stack.shift
name = path_stack.shift
- ns = @namespaces[prefix]
- ns = ns ? ns : ''
+ default_ns = @namespaces[prefix]
+ default_ns = default_ns ? default_ns : ''
nodeset.delete_if do |node|
+ ns = default_ns
# FIXME: This DOUBLES the time XPath searches take
ns = node.namespace( prefix ) if node.node_type == :element and ns == ''
#puts "NS = #{ns.inspect}"
@@ -353,7 +348,7 @@ module REXML
preceding_siblings = all_siblings[ 0 .. current_index-1 ].reverse
#results += expr( path_stack.dclone, preceding_siblings )
end
- nodeset = preceding_siblings
+ nodeset = preceding_siblings || []
node_types = ELEMENTS
when :preceding
@@ -385,10 +380,13 @@ module REXML
return @variables[ var_name ]
# :and, :or, :eq, :neq, :lt, :lteq, :gt, :gteq
+ # TODO: Special case for :or and :and -- not evaluate the right
+ # operand if the left alone determines result (i.e. is true for
+ # :or and false for :and).
when :eq, :neq, :lt, :lteq, :gt, :gteq, :and, :or
- left = expr( path_stack.shift, nodeset, context )
+ left = expr( path_stack.shift, nodeset.dup, context )
#puts "LEFT => #{left.inspect} (#{left.class.name})"
- right = expr( path_stack.shift, nodeset, context )
+ right = expr( path_stack.shift, nodeset.dup, context )
#puts "RIGHT => #{right.inspect} (#{right.class.name})"
res = equality_relational_compare( left, op, right )
#puts "RES => #{res.inspect}"
@@ -472,8 +470,11 @@ module REXML
def descendant_or_self( path_stack, nodeset )
rs = []
+ #puts "#"*80
+ #puts "PATH_STACK = #{path_stack.inspect}"
+ #puts "NODESET = #{nodeset.collect{|n|n.inspect}.inspect}"
d_o_s( path_stack, nodeset, rs )
- #puts "RS = #{rs.collect{|n|n.to_s}.inspect}"
+ #puts "RS = #{rs.collect{|n|n.inspect}.inspect}"
document_order(rs.flatten.compact)
#rs.flatten.compact
end