Support for using namespace-uri() with attributes.

This commit is contained in:
Yorick Peterse 2014-08-21 22:36:18 +02:00
parent 0d41693bfc
commit da09f1296c
2 changed files with 6 additions and 2 deletions

View File

@ -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 ''

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'namespace-uri() function' 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)
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