From acc056eea466c3a8d30414eb8efa9f7e472580f4 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 21 Aug 2014 21:03:28 +0200 Subject: [PATCH] Support for using local-name() on attributes. --- lib/oga/xpath/evaluator.rb | 2 +- spec/oga/xpath/evaluator/calls/local_name_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index e9674e9..d609662 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -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 ## diff --git a/spec/oga/xpath/evaluator/calls/local_name_spec.rb b/spec/oga/xpath/evaluator/calls/local_name_spec.rb index 7d66d4d..b2925d4 100644 --- a/spec/oga/xpath/evaluator/calls/local_name_spec.rb +++ b/spec/oga/xpath/evaluator/calls/local_name_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'local-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('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