Class: Saxon::XSLT::Stylesheet
- Inherits:
-
Object
- Object
- Saxon::XSLT::Stylesheet
- Defined in:
- lib/saxon/xslt.rb
Overview
a Stylesheet transforms input (XML) into output
Class Method Summary collapse
-
.parse(processor, string_or_io, opts = {}) ⇒ Saxon::XSLT::Stylesheet
private
The compiled XSLT stylesheet.
-
.parse_stylesheet_doc(document) ⇒ Saxon::XSLT::Stylesheet
Compile a stylesheet from an existing Saxon::XML instance of an XSLT source.
Instance Method Summary collapse
-
#apply_to(document, params = {}) ⇒ String
Transform an input document and return the result as a string.
-
#initialize(source) ⇒ Stylesheet
constructor
A new instance of Stylesheet.
-
#serialize(document) ⇒ String
Serialise a document to a string.
-
#transform(document, params = {}) ⇒ Saxon::XML::Document
Transform an input document.
Constructor Details
#initialize(source) ⇒ Stylesheet
Returns a new instance of Stylesheet.
38 39 40 41 42 |
# File 'lib/saxon/xslt.rb', line 38 def initialize(source) processor = source.processor compiler = processor.to_java.new_xslt_compiler() @xslt = compiler.compile(source.to_java.as_source) end |
Class Method Details
.parse(processor, string_or_io, opts = {}) ⇒ Saxon::XSLT::Stylesheet
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 the compiled XSLT stylesheet.
23 24 25 26 |
# File 'lib/saxon/xslt.rb', line 23 def self.parse(processor, string_or_io, opts = {}) source = processor.XML(string_or_io, opts) new(source) end |
.parse_stylesheet_doc(document) ⇒ Saxon::XSLT::Stylesheet
Compile a stylesheet from an existing Saxon::XML instance of an XSLT source
33 34 35 |
# File 'lib/saxon/xslt.rb', line 33 def self.parse_stylesheet_doc(document) new(document) end |
Instance Method Details
#apply_to(document, params = {}) ⇒ String
Transform an input document and return the result as a string.
See #transform for details of params handling
72 73 74 |
# File 'lib/saxon/xslt.rb', line 72 def apply_to(document, params = {}) serialize(transform(document, params)) end |
#serialize(document) ⇒ String
Serialise a document to a string
Not the most useful serialiser in the world. Provided for Nokogiri API compatibility
84 85 86 |
# File 'lib/saxon/xslt.rb', line 84 def serialize(document) document.to_s end |
#transform(document, params = {}) ⇒ Saxon::XML::Document
Transform an input document
To pass global parameters you can pass a hash with parameter names as keys and values as XPath expressions as values: to pass a string value, you need to pass it quoted: ‘“’string’”‘. An unquoted string is an XPath reference into the document being transformed.
55 56 57 58 59 60 61 62 63 |
# File 'lib/saxon/xslt.rb', line 55 def transform(document, params = {}) output = S9API::XdmDestination.new transformer = @xslt.load transformer.setInitialContextNode(document.to_java) transformer.setDestination(output) set_params(transformer, document, params) transformer.transform Saxon::XML::Document.new(output.getXdmNode) end |