diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb
index d609662..5a3a8e5 100644
--- a/lib/oga/xpath/evaluator.rb
+++ b/lib/oga/xpath/evaluator.rb
@@ -725,7 +725,7 @@ module Oga
def on_call_name(context, expression = nil)
node = function_node(context, expression)
- if node.is_a?(XML::Element)
+ if node.respond_to?(:name) and node.respond_to?(:namespace)
if node.namespace
return "#{node.namespace.name}:#{node.name}"
else
diff --git a/spec/oga/xpath/evaluator/calls/name_spec.rb b/spec/oga/xpath/evaluator/calls/name_spec.rb
index 46151c3..6a8bfb4 100644
--- a/spec/oga/xpath/evaluator/calls/name_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/name_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'name() function' do
before do
- @document = parse('')
+ @document = parse('')
@evaluator = described_class.new(@document)
end
@@ -16,6 +16,10 @@ describe Oga::XPath::Evaluator do
@evaluator.evaluate('name(root/b)').should == 'b'
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
@evaluator.evaluate('name(root/*)').should == 'x:a'
end