diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb
index 5a3a8e5..27c35e2 100644
--- a/lib/oga/xpath/evaluator.rb
+++ b/lib/oga/xpath/evaluator.rb
@@ -751,7 +751,7 @@ module Oga
def on_call_namespace_uri(context, expression = nil)
node = function_node(context, expression)
- if node.is_a?(XML::Element) and node.namespace
+ if node.respond_to?(:namespace) and node.namespace
return node.namespace.uri
else
return ''
diff --git a/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb b/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
index 54e752b..632da48 100644
--- a/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'namespace-uri() function' do
before do
- @document = parse('')
+ @document = parse('')
@evaluator = described_class.new(@document)
end
@@ -12,6 +12,10 @@ describe Oga::XPath::Evaluator do
@evaluator.evaluate('namespace-uri(root/x:a)').should == 'y'
end
+ example 'return the namespace URI of the "num" attribute' do
+ @evaluator.evaluate('namespace-uri(root/b/@x:num)').should == 'y'
+ end
+
example 'return an empty string when there is no namespace URI' do
@evaluator.evaluate('namespace-uri(root/b)').should == ''
end