Support for using local-name() on attributes.

This commit is contained in:
Yorick Peterse 2014-08-21 21:03:28 +02:00
parent 1dd6416bea
commit acc056eea4
2 changed files with 6 additions and 2 deletions

View File

@ -708,7 +708,7 @@ module Oga
def on_call_local_name(context, expression = nil)
node = function_node(context, expression)
return node.is_a?(XML::Element) ? node.name : ''
return node.respond_to?(:name) ? node.name : ''
end
##

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'local-name() 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
@ -16,6 +16,10 @@ describe Oga::XPath::Evaluator do
@evaluator.evaluate('local-name(root/b)').should == 'b'
end
example 'return the local name for the "num" attribute' do
@evaluator.evaluate('local-name(root/b/@x:num)').should == 'num'
end
example 'return only the name of the first node in the set' do
@evaluator.evaluate('local-name(root/*)').should == 'a'
end