Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Supplying parameters to Ruby XSLT

Here the parameters are supplied as a hash, and if the parameters are not supplied the method will process the xml, and xsl files as normal.

require 'xml/xslt'

class Projxslt
  
  def initialize(sxml, sxsl)
    @sxml = sxml
    @sxsl = sxsl
  end

  def transform(h=nil)
    begin
    xslt = XML::XSLT.new() 
    xslt.xml = @sxml
    xslt.xsl = @sxsl

    if not h.nil? then xslt.parameters = h end
    out = xslt.serve()
    out
    
    rescue
      puts 'problem with xslt data'
    end
  end

end

if __FILE__ == $0
    h = Hash.new
    h["id"] = '1'
    puts h
    pxsl = Projxslt.new("../recordx/recordx.xml", "../xsl/recordx.xsl")
    puts pxsl.transform(h)
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS