From: Wes Gamble Date: 2007-01-24T14:09:02+09:00 Subject: Re: Xalan with Ruby (either command line or via Jrb)? A better solution - use strings for input/output and no need to write files. The return value from this method is the transformed XML. ============================================================================== 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(instring, xsl_file_name) #Load all of the Jars XalanSupport.load_Xalan_libraries #Load all the classes string_reader_class = Rjb::import('java.io.StringReader') string_writer_class = Rjb::import('java.io.StringWriter') stream_source_class = Rjb::import('javax.xml.transform.stream.StreamSource') stream_result_class = Rjb::import('javax.xml.transform.stream.StreamResult') transformer_factory_class = Rjb::import('javax.xml.transform.TransformerFactory') #Set up the input and output input_string_reader = string_reader_class.new(instring) output_string_writer = string_writer_class.new source = stream_source_class.new(input_string_reader) result = stream_result_class.new(output_string_writer) #Create the XSL transformer transformer_factory = transformer_factory_class.newInstance transformer = transformer_factory.newTransformer(stream_source_class.new(xsl_file_name)) transformer.transform(source, result) result.getWriter.getBuffer.toString end end -- Posted via http://www.ruby-forum.com/.