Method: VCDOM::XPath::Internal::Evaluator#evaluate_node_selection

Defined in:
lib/vcdom/xpath/internal/evaluator.rb

#evaluate_node_selection(nodes, cmd) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/vcdom/xpath/internal/evaluator.rb', line 182

def evaluate_node_selection( nodes, cmd )
  # cmd.pred_exprs は nil の可能性あり
  # cmd.node_test_name も nil の可能性あり
  # cmd.node_test_type は :any, :, :processing-instruction など
  new_nodes = Array.new()
  nodes.each do |c_node|
    c_nodes = Array.new()
    # TODO : 軸によって対象となるノードを集める
    if ( node_selection_by_axis_proc = NODE_SELECTION_BY_AXIS_PROCS[ cmd.axis ] ).nil? then
      raise "invalid axis [#{cmd.axis}]"
    end
    node_selection_by_axis_proc.call( c_node, c_nodes )
    # type, name, ns url によって絞り込む
    c_nodes = evaluate_node_selection_sub( c_nodes, cmd )
    # TODO : 軸によって順序を変更?
    if cmd.pred_exprs then
      cmd.pred_exprs.each do |expr|
        c_nodes = evaluate_pred_internal( c_nodes, expr )
      end
    end
    new_nodes.concat c_nodes
  end
  new_nodes.uniq!
  create_node_set_value( *new_nodes )
end