XPath support for absolute paths without tests.

This allows Oga to parse and evaluate the XPath expression "/". This expression
can be used to select just the root node/document.

This fixes #35.
This commit is contained in:
Yorick Peterse committed 2014-09-15 17:06:58 +02:00
1 parent 398aaf68bc
commit b06eadc812
4 files changed
+19 -1

No files matched your search

+2 -1
View File
@@ -131,7 +131,8 @@ module Oga
context = XML::NodeSet.new([@document])
end
return on_path(ast_node, context)
# If the expression is just "/" we'll just return the current context.
return ast_node.children.empty? ? context : on_path(ast_node, context)
end
##
+1
View File
@@ -66,6 +66,7 @@ rule
absolute_path
: T_SLASH path_members { s(:absolute_path, *val[1]) }
| T_SLASH path_member { s(:absolute_path, val[1]) }
| T_SLASH { s(:absolute_path) }
;
# Whenever a bare test is used (e.g. just "A") this actually means "child::A".