Class: Saxon::XSLT::Compiler
- Inherits:
-
Object
- Object
- Saxon::XSLT::Compiler
- Extended by:
- Forwardable
- Defined in:
- lib/saxon/xslt/compiler.rb
Overview
The simplest way to construct an Compiler is to call Processor#xslt_compiler.
processor = Saxon::Processor.create
# Simplest, default options
compiler = processor.xslt_compiler
In order to set compile-time options, declare static compile-time parameters then pass a block to the method using the DSL syntax (see EvaluationContext::DSL
compiler = processor.xslt_compiler {
static_parameters 'param' => 'value'
default_collation 'https://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive/'
}
The static evaluation context for a Compiler cannot be changed, you must create a new one with the context you want. It’s very simple to create a new Compiler based on an existing one. Declaring a parameter with a an existing name overwrites the old value.
new_compiler = compiler.create {
static_parameters 'param' => 'new value'
}
new_compiler.default_collation #=> "https://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive/"
If you wanted to remove a value, you need to start from scratch. You can, of course, extract any data you want from a compiler instance separately and use that to create a new one.
params = compiler.static_parameters
new_compiler = processor.xslt_compiler {
static_parameters params
}
new_compiler.default_collation #=> nil
Once you have a compiler, call #compile and pass in a Source or an existing Saxon::XDM::Node. Parameters and other run-time configuration options can be set using a block in the same way as creating a compiler. You’ll be returned a Executable.
source = Saxon::Source.create('my.xsl')
xslt = compiler.compile(source) {
initial_template_parameters 'param' => 'other value'
}
You can also pass in (or override) parameters at stylesheet execution time, but if you’ll be executing the same stylesheet against many documents with the same initial parameters then setting them at compile time is simpler.
Global and initial template parameters can be set at compiler creation time, compile time, or execution time. Static parameters can only be set at compiler creation or compile time.
xslt = compiler.compile(source) {
static_parameters 'static-param' => 'static value'
global_parameters 'param' => 'global value'
initial_template_parameters 'param' => 'other value'
initial_template_tunnel_parameters 'param' => 'tunnel value'
}
Instance Attribute Summary collapse
-
#declared_collations ⇒ Hash<String => java.text.Collator>
readonly
Declared collations as URI => Collator hash.
-
#default_collation ⇒ String
readonly
The URI of the default declared collation.
-
#static_parameters ⇒ Hash<Saxon::QName => Saxon::XDM::Value, Saxon::XDM::Node,
readonly
Saxon::XDM::AtomicValue>] parameters required at compile time as QName => value hash.
Class Method Summary collapse
-
.create(processor) { ... } ⇒ Saxon::XSLT::Compiler
Create a new
XSLT::Compiler
using the supplied Processor.
Instance Method Summary collapse
-
#compile(source) { ... } ⇒ Saxon::XSLT::Executable
The executable stylesheet.
-
#create { ... } ⇒ Saxon::XSLT::Compiler
Allows the creation of a new Compiler starting from a copy of this Compiler’s static context.
-
#initialize(s9_processor, evaluation_context) ⇒ Compiler
constructor
private
A new instance of Compiler.
Constructor Details
#initialize(s9_processor, evaluation_context) ⇒ Compiler
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 Compiler.
91 92 93 |
# File 'lib/saxon/xslt/compiler.rb', line 91 def initialize(s9_processor, evaluation_context) @s9_processor, @evaluation_context = s9_processor, evaluation_context end |
Instance Attribute Details
#declared_collations ⇒ Hash<String => java.text.Collator> (readonly)
Returns declared collations as URI => Collator hash.
|
# File 'lib/saxon/xslt/compiler.rb', line 96
|
#default_collation ⇒ String (readonly)
Returns the URI of the default declared collation.
|
# File 'lib/saxon/xslt/compiler.rb', line 96
|
#static_parameters ⇒ Hash<Saxon::QName => Saxon::XDM::Value, Saxon::XDM::Node, (readonly)
Saxon::XDM::AtomicValue>] parameters required at compile time as QName => value hash
|
# File 'lib/saxon/xslt/compiler.rb', line 96
|
Class Method Details
.create(processor) { ... } ⇒ Saxon::XSLT::Compiler
Create a new XSLT::Compiler
using the supplied Processor. Passing a block gives access to a DSL for setting up the compiler’s static context.
76 77 78 79 |
# File 'lib/saxon/xslt/compiler.rb', line 76 def self.create(processor, &block) evaluation_context = XSLT::EvaluationContext.define(block) new(processor.to_java, evaluation_context) end |
Instance Method Details
#compile(source) { ... } ⇒ Saxon::XSLT::Executable
Returns the executable stylesheet.
107 108 109 110 111 112 113 114 |
# File 'lib/saxon/xslt/compiler.rb', line 107 def compile(source, &block) new_evaluation_context = evaluation_context.define(block) s9_compiler = new_compiler(new_evaluation_context) Saxon::XSLT::Executable.new( s9_compiler.compile(source.to_java), new_evaluation_context ) end |
#create { ... } ⇒ Saxon::XSLT::Compiler
Allows the creation of a new Saxon::XSLT::Compiler starting from a copy of this Compiler’s static context. As with create, passing a block gives access to a DSL for setting up the compiler’s static context.
122 123 124 125 |
# File 'lib/saxon/xslt/compiler.rb', line 122 def create(&block) new_evaluation_context = evaluation_context.define(block) self.class.new(@s9_processor, new_evaluation_context) end |