Class: Saxon::XPath::Executable

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • s9_xpath_executable (net.sf.saxon.s9api.XPathExecutable)

    the Saxon compiled XPath object

  • static_context (XPath::StaticContext)

    the XPath’s static context



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_contextXPath::StaticContext (readonly)

Returns the XPath’s static context.

Returns:



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.

Parameters:

Returns:

  • (Enumerator)

    an Enumerator over the items in the result sequence



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.

Parameters:

Returns:



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_javanet.sf.saxon.s9api.XPathExecutable

Returns the underlying Saxon XPathExecutable.

Returns:

  • (net.sf.saxon.s9api.XPathExecutable)

    the underlying Saxon XPathExecutable



67
68
69
# File 'lib/saxon/xpath/executable.rb', line 67

def to_java
  @s9_xpath_executable
end