Class: Saxon::XPath::Executable
- Inherits:
-
Object
- Object
- Saxon::XPath::Executable
- Defined in:
- lib/saxon/xpath/executable.rb
Overview
Represents a compiled XPath query ready to be executed. An Executable is created by compiling an XPath expression with Compiler#compile.
To run the XPath::Executable
you can call #evaluate, to generate an Saxon::XDM::Value of the results, or you can call #as_enum to return an Enumerator over the results.
processor = Saxon::Processor.create
compiler = processor.xpath_compiler
xpath = compiler.compile('//element[@attr = $var]')
matches = xpath.evaluate(document_node, {'var' => 'the value'}) #=> Saxon::XDM::Value
xpath.as_enum(document_node, {'var' => 'the value'}).each do |node|
...
end
Instance Attribute Summary collapse
-
#static_context ⇒ XPath::StaticContext
readonly
The XPath’s static context.
Instance Method Summary collapse
-
#as_enum(context_item, variables = {}) ⇒ Enumerator
Evaluate the XPath against the context node given and return an
Enumerator
over the result. -
#evaluate(context_item, variables = {}) ⇒ Saxon::XDM::Value
Evaluate the XPath against the context node given and return the result.
-
#initialize(s9_xpath_executable, static_context) ⇒ Executable
constructor
private
A new instance of Executable.
-
#to_java ⇒ net.sf.saxon.s9api.XPathExecutable
The underlying Saxon
XPathExecutable
.
Constructor Details
#initialize(s9_xpath_executable, static_context) ⇒ Executable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Executable.
31 32 33 |
# File 'lib/saxon/xpath/executable.rb', line 31 def initialize(s9_xpath_executable, static_context) @s9_xpath_executable, @static_context = s9_xpath_executable, static_context end |
Instance Attribute Details
#static_context ⇒ XPath::StaticContext (readonly)
Returns the XPath’s static context.
24 25 26 |
# File 'lib/saxon/xpath/executable.rb', line 24 def static_context @static_context end |
Instance Method Details
#as_enum(context_item, variables = {}) ⇒ Enumerator
Evaluate the XPath against the context node given and return an Enumerator
over the result.
44 45 46 47 |
# File 'lib/saxon/xpath/executable.rb', line 44 def as_enum(context_item, variables = {}) generate_selector(context_item, variables).iterator.lazy. map { |s9_xdm_object| Saxon::XDM.Value(s9_xdm_object) } end |
#evaluate(context_item, variables = {}) ⇒ Saxon::XDM::Value
Evaluate the XPath against the context node given and return the result.
If the result is a single item, then that will be returned directly (e.g. an Saxon::XDM::Node or an Saxon::XDM::AtomicValue). If the result is an empty sequence then Saxon::XDM::EmptySequence is returned.
60 61 62 63 |
# File 'lib/saxon/xpath/executable.rb', line 60 def evaluate(context_item, variables = {}) s9_xdm_value = generate_selector(context_item, variables).evaluate Saxon::XDM.Value(s9_xdm_value) end |
#to_java ⇒ net.sf.saxon.s9api.XPathExecutable
Returns the underlying Saxon XPathExecutable
.
67 68 69 |
# File 'lib/saxon/xpath/executable.rb', line 67 def to_java @s9_xpath_executable end |