dynarex-xslt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dynarex-xslt.rb +69 -0
  2. metadata +56 -0
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: recordx-xslt.rb
4
+
5
+ require 'rexle-builder'
6
+ require 'rexle'
7
+
8
+ class DynarexXSLT
9
+
10
+ attr_accessor :schema, :xslt_schema
11
+
12
+ def initialize(options={})
13
+ o = {schema: '', xslt_schema: ''}.merge(options)
14
+ @schema, @xslt_schema = o.values
15
+ end
16
+
17
+ def to_xslt()
18
+
19
+ a_element = @schema.split('/').map{|x| x[/\w+/]}
20
+
21
+ a_html = @xslt_schema.split('/').map do |x|
22
+
23
+ name = x[/\w+/]
24
+ children = ($')[/^[\(\[]([^\)\]]+)[\)\]]$/,1]
25
+ list = children.split(',').map {|y| y.split(':') } if children
26
+
27
+ [name, list]
28
+ end
29
+
30
+ a = a_element.zip(a_html)
31
+
32
+ xml = RexleBuilder.new
33
+ raw_a = xml.xsl_stylesheet(xmlns_xsl: "http://www.w3.org/1999/XSL/Transform", version: "1.0") do
34
+ xml.xsl_output(method: "xml", indent: "yes")
35
+
36
+ xml.xsl_template(match: a[0][0]) do
37
+ xml.send a[0][1][0].to_sym do
38
+ xml.xsl_apply_templates(select: 'summary')
39
+ xml.xsl_apply_templates(select: 'records')
40
+ end
41
+ end
42
+
43
+ xml.xsl_template(match: a[0][0] + '/summary') do
44
+ a[0][1][1].each do |element, field|
45
+ xml.send (element.strip).to_sym do
46
+ xml.xsl_value_of(select: field)
47
+ end
48
+ end
49
+ end
50
+
51
+ xml.xsl_template(match: 'records/' + a[1][0][0]) do
52
+ xml.send a[1][1][0].to_sym do
53
+ a[1][1][1].each do |element, field|
54
+ xml.send element.to_sym do
55
+ xml.xsl_value_of(select: field)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ Rexle.new(raw_a).xml(pretty: true).gsub('xsl_apply_templates',\
64
+ 'xsl:apply-templates').gsub('xsl_value_of','xsl:value-of').\
65
+ gsub('xsl_template','xsl:template')
66
+
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynarex-xslt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - James Robertson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-03-15 00:00:00 +00:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email:
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/dynarex-xslt.rb
27
+ has_rdoc: true
28
+ homepage:
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.5.2
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: dynarex-xslt
55
+ test_files: []
56
+