Skip to content

Commit

Permalink
support querying HTML5 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Oct 15, 2018
1 parent c71de35 commit 7a3fdfe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/xpath/renderer.rb
Expand Up @@ -59,7 +59,11 @@ def where(on, condition)
end

def attribute(current, name)
"#{current}/@#{name}"
if valid_xml_name?(name)
"#{current}/@#{name}"
else
"#{current}/attribute::*[local-name(.) = #{string_literal(name)}]"
end
end

def binary_operator(name, left, right)
Expand Down Expand Up @@ -112,5 +116,9 @@ def with_element_conditions(expression, element_names)
"#{expression}*"
end
end

def valid_xml_name?(name)
name =~ /^[a-zA-Z_:][a-zA-Z0-9_:\.\-]*$/
end
end
end

0 comments on commit 7a3fdfe

Please sign in to comment.