Class: Simplyx::XsltProcessor
- Inherits:
-
Object
- Object
- Simplyx::XsltProcessor
- Defined in:
- lib/simplyx/jxslt.rb
Direct Known Subclasses
Class Method Summary collapse
-
.perform_transformation(xsl_file, xml_file, transformer_parameters = nil) ⇒ Object
This is used to perform xsltransformation, you should pass it the xsl and xml file paths, and some parameters (an hash) if you need them.
Instance Method Summary collapse
Class Method Details
.perform_transformation(xsl_file, xml_file, transformer_parameters = nil) ⇒ Object
This is used to perform xsltransformation, you should pass it the xsl and xml file paths, and some parameters (an hash) if you need them
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simplyx/jxslt.rb', line 17 def self.perform_transformation(xsl_file, xml_file, transformer_parameters=nil) file = File.open(xsl_file) xsl = file.read file.close file = File.open(xml_file) xml = file.read file.close saxon = Simplyx::Saxon.new output = saxon.transform(xsl, xml, nil, = {:in => "string", :out => "string", :xsl => "string", :transformer_parameters => transformer_parameters}) end |
Instance Method Details
#transform(xslt, infile, outfile, options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/simplyx/jxslt.rb', line 28 def transform(xslt, infile, outfile, ) if [:in] == "stream" in_var = StreamSource.new(infile) else sr = java.io.StringReader.new(infile) in_var = StreamSource.new(sr) end if [:out] == "stream" out_var = StreamResult.new(outfile) else sw = java.io.StringWriter.new() out_var = StreamResult.new(sw) end if [:xslt] == "stream" xslt_var = StreamSource.new(xslt) else sxs = java.io.StringReader.new(xslt) xslt_var = StreamSource.new(sxs) end transformer = @tf.newTransformer(xslt_var) unless [:transformer_parameters].nil? [:transformer_parameters].each do |key, value| transformer.setParameter(key, java.lang.String.new(value)) end end transformer.transform(in_var, out_var) if [:out] != "stream" outfile = sw.toString() end end |