-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxslt
60 lines (49 loc) · 1.61 KB
/
xslt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
# frozen_string_literal: true
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
root_dir = File.dirname(script_dir)
require_relative File.join(root_dir, "lib", "logger")
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
require 'optparse'
require 'ostruct'
# Process the script parameters.
options = OpenStruct.new
options.output_method = :html
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [-h] [-m output_method] xsl_file xml_file [xml_file...]"
opts.on('-m', '--output_method html|xml', 'Output method html|xml') do |output_method|
options.output_method = output_method
end
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(opts)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 2
script_logger.info(option_parser.help)
exit(0)
end
xsl_file = File.expand_path(ARGV[0])
unless File.file?(xsl_file)
script_logger.error("invalid XSL file #{xsl_file}")
exit(1)
end
require_relative File.join(root_dir, 'lib', 'xslt')
require_relative File.join(root_dir, 'lib', 'xml', 'util')
xml_file_list = ARGV[1..-1]
xml_file_list.each do |xml_file|
xml_file = File.expand_path(xml_file)
unless File.file?(xml_file)
script_logger.error("invalid file #{xml_file}")
next
end
output_file = File.join(File.dirname(xml_file), File.basename(xml_file, ".*") + \
"_transformed." + options.output_method.to_s)
UMPTG::XSLT.transform(
xslpath: xsl_file,
srcpath: xml_file,
destpath: output_file
)
end