Wes said:
Does anyone have any experience will using Xalan from a Ruby program
(Rails app. especially useful)?
I'm willing to entertain running command lines but would like to use Jrb
(I've already got that working).
I'd consider JRuby but feel like that might be too heavyweight.
Any advice/feedback would be appreciated.
Thanks,
Wes
I seem to have gotten this working - a basic Xalan XSL transform from
one file to another. The do_XSL_transform takes the input file name,
output file name, and XSL stylesheet file name as parameters.
Wes
==========================================
require 'rjb'
require_gem 'rjb', '>= 1.0.2'
module XalanSupport
def XalanSupport.load_Xalan_libraries
['serializer.jar', 'xml-apis.jar', 'xercesImpl.jar',
'xalan.jar'].each do |lib_name|
Rjb::load("#{RAILS_ROOT}/lib/#{lib_name}", ['-Xmx512M'])
end
end
def XalanSupport.do_XSL_transform(infile, outfile, xsl)
#Load all of the Jars
XalanSupport.load_Xalan_libraries
#Load all the classes
stream_source_class =
Rjb::import('javax.xml.transform.stream.StreamSource')
stream_result_class =
Rjb::import('javax.xml.transform.stream.StreamResult')
file_output_stream_class = Rjb::import('java.io.FileOutputStream')
transformer_factory_class =
Rjb::import('javax.xml.transform.TransformerFactory')
#Create the XSL transformer
transformer_factory = transformer_factory_class.newInstance
transformer =
transformer_factory.newTransformer(stream_source_class.new(xsl))
#Set up the input and output
source = stream_source_class.new(infile)
result =
stream_result_class.new(file_output_stream_class.new(outfile))
transformer.transform(source, result)
end
end