Class: Saxon::XSLT::Executable
- Inherits:
-
Object
- Object
- Saxon::XSLT::Executable
- Extended by:
- Forwardable, FeatureFlags::Helpers
- Defined in:
- lib/saxon/xslt/executable.rb,
lib/saxon/nokogiri.rb
Overview
Represents a compiled XSLT stylesheet ready to be executed
Once you have a compiled stylesheet, then it can be executed against a source document in a variety of ways.
First, you can use the traditional *apply templates* ,method, which was the only way in XSLT 1.
input = Saxon::Source.create('input.xml')
result = xslt.apply_templates(input)
Next, you can call a specific named template (new in XSLT 2).
result = xslt.call_template('template-name')
Note that there’s no input document here. If your XSLT needs a global context item set when you invoke it via a named template, then you can do that, too:
input = processor.XML('input.xml')
result = xslt.call_template('template-name', {
global_context_item: input
})
Global and initial template parameters can be set at compiler creation time, compile time, or execution time.
Initial template parameters relate to parameters passed to the first template run (either the first template matched when called with #apply_templates, or the named template called with #call_template).
Initial template parameters are essentially implied <xsl:with-parameter tunnel=“no”> elements. Initial template tunnel parameters are implied <xsl:with-parameter tunnel=“yes”> elements.
xslt.apply_templates(input, {
global_parameters: {'param' => 'global value'},
initial_template_parameters: {'param' => 'other value'},
initial_template_tunnel_parameters: {'param' => 'tunnel value'}
})
Remember that if you need to use a parameter name which uses a namespace prefix, you must use an explicit QName to refer to it.
Instance Method Summary collapse
-
#apply_templates(source, opts = {}) ⇒ Saxon::XSLT::Invocation
Run the XSLT by applying templates against the provided Source or Saxon::XDM::Node.
-
#apply_to(doc_node, params = {}) ⇒ String
Provided for Nokogiri API compatibility.
-
#call_function(function_name, opts = {}) ⇒ Saxon::XSLT::Invocation
Invoke a named function in the XSLT.
-
#call_template(template_name = nil, opts = {}) ⇒ Saxon::XSLT::Invocation
Run the XSLT by calling the named template.
-
#initialize(s9_xslt_executable, evaluation_context) ⇒ Executable
constructor
private
A new instance of Executable.
-
#serialize(doc_node) ⇒ String
Provided for Nokogiri API compatibility.
-
#serializer ⇒ Saxon::Serializer::Object
Create a Serializer::Object configured using the options that were set by <xsl:output>.
-
#to_java ⇒ net.sf.saxon.s9api.XsltExecutable
The underlying Saxon
XsltExecutable
. -
#transform(doc_node, params = {}) ⇒ Saxon::XDM::Value
Provided for Nokogiri API compatibility.
Methods included from FeatureFlags::Helpers
Constructor Details
#initialize(s9_xslt_executable, evaluation_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.
67 68 69 |
# File 'lib/saxon/xslt/executable.rb', line 67 def initialize(s9_xslt_executable, evaluation_context) @s9_xslt_executable, @evaluation_context = s9_xslt_executable, evaluation_context end |
Instance Method Details
#apply_templates(source, opts = {}) ⇒ Saxon::XSLT::Invocation
Any QNames supplied as strings MUST be resolvable as a QName
Run the XSLT by applying templates against the provided Source or Saxon::XDM::Node.
without extra information, so they must be prefix-less (so, ‘name’, and never ‘ns:name’)
103 104 105 |
# File 'lib/saxon/xslt/executable.rb', line 103 def apply_templates(source, opts = {}) transformation(opts).apply_templates(source) end |
#apply_to(doc_node, params = {}) ⇒ String
Provided for Nokogiri API compatibility. Cannot use many XSLT 2 and 3 features as a result.
Transform the input document by applying templates as in XSLT 1, and then serializing the result to a string using the serialization options set in the XSLT stylesheet’s <xsl:output/>.
33 34 35 |
# File 'lib/saxon/nokogiri.rb', line 33 def apply_to(doc_node, params = {}) apply_templates(doc_node, v1_parameters(params)).to_s end |
#call_function(function_name, opts = {}) ⇒ Saxon::XSLT::Invocation
the function you’re calling needs to be have been defined with visibility=“public” or visibility=“final”
Invoke a named function in the XSLT.
162 163 164 165 |
# File 'lib/saxon/xslt/executable.rb', line 162 def call_function(function_name, opts = {}) args = opts.fetch(:args, []) transformation(opts.reject { |k, v| k == :args }).call_function(function_name, args) end |
#call_template(template_name = nil, opts = {}) ⇒ Saxon::XSLT::Invocation
Any QNames supplied as Strings (e.g. for the template name)
Run the XSLT by calling the named template.
MUST be resolvable as a QName without extra information, so they must be prefix-less (so, ‘name’, and never ‘ns:name’)
137 138 139 |
# File 'lib/saxon/xslt/executable.rb', line 137 def call_template(template_name = nil, opts = {}) transformation(opts).call_template(template_name) end |
#serialize(doc_node) ⇒ String
Provided for Nokogiri API compatibility. Cannot use many XSLT 2 and 3 features as a result.
Serialize the input document to a string using the serialization options set in the XSLT stylesheet’s <xsl:output/>.
45 46 47 48 49 |
# File 'lib/saxon/nokogiri.rb', line 45 def serialize(doc_node) s9_transformer = @s9_xslt_executable.load30 serializer = Saxon::Serializer::Object.new(s9_transformer.newSerializer) serializer.serialize(doc_node.to_java) end |
#serializer ⇒ Saxon::Serializer::Object
Create a Serializer::Object configured using the options that were set by <xsl:output>.
171 172 173 |
# File 'lib/saxon/xslt/executable.rb', line 171 def serializer Saxon::Serializer::Object.new(@s9_xslt_executable.load30.newSerializer) end |
#to_java ⇒ net.sf.saxon.s9api.XsltExecutable
Returns the underlying Saxon XsltExecutable
.
178 179 180 |
# File 'lib/saxon/xslt/executable.rb', line 178 def to_java @s9_xslt_executable end |
#transform(doc_node, params = {}) ⇒ Saxon::XDM::Value
Provided for Nokogiri API compatibility. Cannot use many XSLT 2 and 3 features as a result.
Transform the input document by applying templates as in XSLT 1. All parameters will be interpreted as Strings
17 18 19 |
# File 'lib/saxon/nokogiri.rb', line 17 def transform(doc_node, params = {}) apply_templates(doc_node, v1_parameters(params)).xdm_value end |