Class: Saxon::XPath::StaticContext::DSL

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/saxon/xpath/static_context.rb

Overview

Provides the hooks for constructing a Saxon::XPath::StaticContext with a DSL.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#args_hash, #initialize

Class Method Details

.define(block, args = {}) ⇒ Saxon::XPath::StaticContext

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.

Create an instance based on the args hash, and execute the passed in Proc/lambda against it using #instance_exec and return a new Saxon::XPath::StaticContext with the results

Parameters:

  • block (Proc)

    a Proc/lambda (or to_proc‘d containing DSL calls

Returns:



57
58
59
60
61
# File 'lib/saxon/xpath/static_context.rb', line 57

def self.define(block, args = {})
  dsl = new(args)
  dsl.instance_exec(&block) unless block.nil?
  StaticContext.new(dsl.args_hash)
end

Instance Method Details

#default_collation(collation_uri) ⇒ Object

Set the default Collation to use. This should be one of the special collation URIs Saxon recognises, or one that has been registered using Saxon::Processor#declare_collations on the Processor that created the Compiler this context is for.

Parameters:

  • collation_uri (String)

    The URI of the Collation to set as the default



69
70
71
# File 'lib/saxon/xpath/static_context.rb', line 69

def default_collation(collation_uri)
  @default_collation = collation_uri
end

#namespace(namespaces = {}) ⇒ Object

Bind prefixes to namespace URIs

Parameters:

  • namespaces (Hash{String, Symbol => String}) (defaults to: {})


76
77
78
# File 'lib/saxon/xpath/static_context.rb', line 76

def namespace(namespaces = {})
  @declared_namespaces = @declared_namespaces.merge(namespaces.map { |k, v| [k.to_s, v] }.to_h).freeze
end

#variable(qname, sequence_type = nil) ⇒ Object

Declare a XPath variable’s existence in the context

Parameters:

  • qname (String, Saxon::QName)

    The name of the variable as explicit QName or prefix:name string form. The string form requires the namespace prefix to have already been declared with #namespace

  • sequence_type (String, Saxon::SequenceType, null) (defaults to: nil)

    The type of the variable, either as a string using the same form as an XSLT as="" type definition, or as a SequenceType directly.

    If it’s nil, then the default item()* – anything – type declaration is used



90
91
92
93
94
95
# File 'lib/saxon/xpath/static_context.rb', line 90

def variable(qname, sequence_type = nil)
  qname = resolve_variable_qname(qname)
  @declared_variables = @declared_variables.merge({
    qname => resolve_variable_declaration(qname, sequence_type)
  }).freeze
end