From: Keith Fahlgren Date: 2006-02-16T22:39:33+09:00 Subject: Re: XML Builder - why? On Thursday 16 February 2006 1:33 am, eastcoastcoder@gmail.com wrote: > I see that a lot of Rubyists like using XML Builder to generate XML. > why took this even further with markaby to generate HTML. Well, I don't really use Builder for HTML, but generate quite a lot of XML with it. Here's one simple use I like (make XSLT search-and-replace with simple YAML): #!/usr/bin/env ruby require 'yaml' require 'rubygems' require_gem 'builder', '~> 1.2' ARGV.each do |arg| yml = YAML::load(File.open(arg)) b = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2) b.xsl :stylesheet, "version" =>"1.0", "xmlns:xsl" =>"http://www.w3.org/1999/XSL/Transform" do b.xsl :output, "method" =>"xml", "encoding"=>"ascii", "cdata-section-elements=>"_facet" b.comment!("Default Rule") b.xsl :template, "match"=>"@*|node()" do b.xsl :copy do b.xsl :"apply-templates", "select"=>"@*|node()" end # xsl:template end # xsl:copy yml.each { |outkey, outvalue| outvalue.each { |key, value| b.xsl :template, "match"=>"#{outkey}[. = "`#{key}'"]" do b.xsl :copy, "`#{value}'" # b.xsl :message, "Matched #{key}" end } # end of outvalue.each } # end of yaml.each end end