Support for using name() with attributes.
This commit is contained in:
		
							parent
							
								
									acc056eea4
								
							
						
					
					
						commit
						0d41693bfc
					
				| 
						 | 
					@ -725,7 +725,7 @@ module Oga
 | 
				
			||||||
      def on_call_name(context, expression = nil)
 | 
					      def on_call_name(context, expression = nil)
 | 
				
			||||||
        node = function_node(context, expression)
 | 
					        node = function_node(context, expression)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if node.is_a?(XML::Element)
 | 
					        if node.respond_to?(:name) and node.respond_to?(:namespace)
 | 
				
			||||||
          if node.namespace
 | 
					          if node.namespace
 | 
				
			||||||
            return "#{node.namespace.name}:#{node.name}"
 | 
					            return "#{node.namespace.name}:#{node.name}"
 | 
				
			||||||
          else
 | 
					          else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ require 'spec_helper'
 | 
				
			||||||
describe Oga::XPath::Evaluator do
 | 
					describe Oga::XPath::Evaluator do
 | 
				
			||||||
  context 'name() function' do
 | 
					  context 'name() function' do
 | 
				
			||||||
    before do
 | 
					    before do
 | 
				
			||||||
      @document  = parse('<root xmlns:x="y"><x:a></x:a><b></b></root>')
 | 
					      @document  = parse('<root xmlns:x="y"><x:a></x:a><b x:num="10"></b></root>')
 | 
				
			||||||
      @evaluator = described_class.new(@document)
 | 
					      @evaluator = described_class.new(@document)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,10 @@ describe Oga::XPath::Evaluator do
 | 
				
			||||||
        @evaluator.evaluate('name(root/b)').should == 'b'
 | 
					        @evaluator.evaluate('name(root/b)').should == 'b'
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      example 'return the local name for the "num" attribute' do
 | 
				
			||||||
 | 
					        @evaluator.evaluate('name(root/b/@x:num)').should == 'x:num'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      example 'return only the name of the first node in the set' do
 | 
					      example 'return only the name of the first node in the set' do
 | 
				
			||||||
        @evaluator.evaluate('name(root/*)').should == 'x:a'
 | 
					        @evaluator.evaluate('name(root/*)').should == 'x:a'
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue