Fernando P. wrote:
Hi. I’m working with XML and REXML and I could use some help in two
particular issues:
First, I want to display a REXML::Document object.
Last time I checked, Ruby had incomplete native XSLT support. You need
to
get either msxsl.exe by Microsoft or xsltproc by everyone else. Then
pipe
your XML thru an XSLT template to re-render everything in XHTML.
Below my sig is a snip of code that detects which one you have and calls
it
correctly.
To diff XML, you could google for “diff XML”, “XMLunit”, or “XSLTunit”.
I
have not tried either, but as diffing content is a major aspect of
testing,
the XSLTunit ought to show how to do it.
–
Phlip
Test Driven Ajax (on Rails) [Book]
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax
$win32Exts = %w{.exe .com .bat}
Adapted from Michael G.'s FileWhich on RubyGarden
def which(prog, path=ENV[‘PATH’])
path.split(File::PATH_SEPARATOR).each {|dir|
Windows checks against specific extensions
if File::ALT_SEPARATOR
ext = $win32Exts.find{|ext|
if prog.include?(‘.’) # Assume extension already included
f = File.join(dir,prog)
else
f = File.join(dir,prog+ext)
end
File.executable?(f) && !File.directory?(f)
}
if ext
# Use backslashes, not forward slashes
if prog.include?(‘.’) # Assume extension already included
f = File.join( dir, prog ).gsub(///,‘\’)
else
f = File.join( dir, prog + ext ).gsub(///,‘\’)
end
return f
end
else
f = File.join(dir,prog)
# Avoid /usr/lib/ruby, for example
if File.executable?(f) && !File.directory?(f)
return File::join( dir, prog )
end
end
}
nil
end
def callXsl(xslFile, xmlFile, param = {})
msxsl = which(‘msxsl’)
xsltproc = which(‘xsltproc’)
if xsltproc != nil then
params = ‘’
param.each { |p,v|
params += "--param #{p} \"'#{v}'\" "
}
xhtml = `#{xsltproc} #{params} #{xslFile} #{xmlFile} 2>&1`
return xhtml
elsif msxsl != nil then
params = ‘’
param.each { |p,v|
params += p
params += '="'
params += v
params += '" '
}
msxsl.gsub!'\\\\', '/'
cmd = "#{msxsl} #{xmlFile} #{xslFile} #{params}"
xhtml = `#{cmd} 2>&1`
return xhtml
else
return ‘please install either msxsl or xsltproc’
end
end
def _Transform(xmlFile, xslFile, param)
return callXsl(xslFile, xmlFile, param = {})
end