rexslt 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/rexslt.rb +166 -156
- data.tar.gz.sig +0 -0
- metadata +39 -39
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725f7f09d8f7723708b9d830560c57c355f4e9b4477b5b0175b788a1f4d23577
|
4
|
+
data.tar.gz: 60662b52e4e3a423da34faf3b95f7f327ddc6b3732a4335a4601baa7da02a0eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc0706519a8ef26fed3262a66b5166b88cc7b13543f85038e9f09009f504c69b3d3a9e4dc99fa4a6dad9025ef34cca760cd1c3ccee219602bcc1c7b79803104
|
7
|
+
data.tar.gz: a767396429dcea36fedb2f19cf04523be1a6d9df614f6b415da1851a361555fd80e19d9fcab8be284513be53a21cd229babd0e915f1fb0c090e19d7651a5eeff
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rexslt.rb
CHANGED
@@ -3,39 +3,40 @@
|
|
3
3
|
# file: rexslt.rb
|
4
4
|
|
5
5
|
require 'rexle'
|
6
|
-
require '
|
6
|
+
require 'rxfreader'
|
7
7
|
require 'logger'
|
8
8
|
|
9
9
|
|
10
10
|
# modifications:
|
11
11
|
#
|
12
|
-
#
|
12
|
+
# 22-Feb-2022: minor improvement: Replaced RXFHelper with RXFReader.
|
13
|
+
# 01-Feb-2019: bug fix: new line characters are no longer stripped
|
13
14
|
# between XSL elements
|
14
15
|
# bug fix: An attribute variable value is now returned correctly
|
15
16
|
# 19-Jan-2018: feature: Implemented Rexslt#to_xml which returns pretty XML
|
16
|
-
# 16-Sep-2017: improvement: all predicates in an xsl:choose
|
17
|
+
# 16-Sep-2017: improvement: all predicates in an xsl:choose
|
17
18
|
# condition now must be true
|
18
19
|
# 15-Sep-2017: feature: Implemented xsl_call_template
|
19
|
-
# 21-May-2016: bug fix: An update to the Rexle gem regarding the new
|
20
|
-
# Rexle::Element::Attribute datatype caused the sort_by code
|
20
|
+
# 21-May-2016: bug fix: An update to the Rexle gem regarding the new
|
21
|
+
# Rexle::Element::Attribute datatype caused the sort_by code
|
21
22
|
# to break. This has now been rectified.
|
22
|
-
# 04-May-2016: bug fix: disabled the method which strips out all new
|
23
|
-
# line spaces, and replaced it with a statement in the
|
24
|
-
# read_raw_text() method which strips out space before and
|
23
|
+
# 04-May-2016: bug fix: disabled the method which strips out all new
|
24
|
+
# line spaces, and replaced it with a statement in the
|
25
|
+
# read_raw_text() method which strips out space before and
|
25
26
|
# after the text
|
26
|
-
# 03-May-2016: A returned HTML document will no longer include an
|
27
|
+
# 03-May-2016: A returned HTML document will no longer include an
|
27
28
|
# XML declaration by default
|
28
|
-
# 30-Apr-2016: bug fix: This class can now be executed within an
|
29
|
+
# 30-Apr-2016: bug fix: This class can now be executed within an
|
29
30
|
# eval statement which runs within another class
|
30
|
-
# 24-Apr-2016: The position() function is now supported within an
|
31
|
+
# 24-Apr-2016: The position() function is now supported within an
|
31
32
|
# xsl:value-of select attribute
|
32
|
-
# An xsl:attribute value can now be rendered using
|
33
|
+
# An xsl:attribute value can now be rendered using
|
33
34
|
# an xsl:text element
|
34
35
|
|
35
36
|
module RexPath
|
36
|
-
|
37
|
+
|
37
38
|
refine Rexle::Element do
|
38
|
-
|
39
|
+
|
39
40
|
def to_xpath(option=nil)
|
40
41
|
def attribute_scan(node)
|
41
42
|
result = ''
|
@@ -63,38 +64,38 @@ end
|
|
63
64
|
class Rexslt
|
64
65
|
using RexPath
|
65
66
|
using ColouredText
|
66
|
-
|
67
|
-
def initialize(xsl, xml, raw_params={}, debug: false)
|
68
|
-
|
67
|
+
|
68
|
+
def initialize(xsl, xml, raw_params={}, debug: false)
|
69
|
+
|
69
70
|
## debugging variables
|
70
|
-
|
71
|
+
|
71
72
|
@rn = 0
|
72
73
|
@rre = 0
|
73
74
|
|
74
75
|
super()
|
75
76
|
puts 'before options'.info if @debug
|
76
77
|
@options = {}
|
77
|
-
|
78
|
+
|
78
79
|
params = raw_params.merge({debug: false})
|
79
80
|
@debug = debug
|
80
|
-
custom_params = params.inject({}){|r,x| r.merge(Hash[x[0].to_s,x[1]])}
|
81
|
+
custom_params = params.inject({}){|r,x| r.merge(Hash[x[0].to_s,x[1]])}
|
81
82
|
puts 'before xsl_transform'.info if @debug
|
82
83
|
|
83
|
-
xslt_transform(*[xsl, xml].map{|x|
|
84
|
+
xslt_transform(*[xsl, xml].map{|x| RXFReader.read(x).first}, custom_params)
|
84
85
|
end
|
85
|
-
|
86
|
+
|
86
87
|
def to_s(options={})
|
87
88
|
@doc.to_s(@options.merge(options)).sub(/<root4>/,'').sub(/<\/root4>$/m,'').lstrip
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
def to_doc(); @doc; end
|
91
|
-
|
92
|
+
|
92
93
|
def to_xml()
|
93
|
-
@doc.root.xml(pretty: true).sub(/<root4>/,'').sub(/<\/root4>$/m,'')
|
94
|
+
@doc.root.xml(pretty: true).sub(/<root4>/,'').sub(/<\/root4>$/m,'')
|
94
95
|
end
|
95
96
|
|
96
97
|
private
|
97
|
-
|
98
|
+
|
98
99
|
def filter_out_spaces(e)
|
99
100
|
|
100
101
|
e.children.each do |x|
|
@@ -107,10 +108,10 @@ class Rexslt
|
|
107
108
|
elsif x.is_a? Rexle::Element and x.children.length > 0 then
|
108
109
|
filter_out_spaces x
|
109
110
|
end
|
110
|
-
|
111
|
+
|
111
112
|
end
|
112
113
|
end
|
113
|
-
|
114
|
+
|
114
115
|
|
115
116
|
def xsl_apply_templates(element, x, doc_element, indent, i)
|
116
117
|
|
@@ -120,11 +121,11 @@ class Rexslt
|
|
120
121
|
|
121
122
|
keypath = node.to_xpath :no_cond
|
122
123
|
matched_node = nil
|
123
|
-
|
124
|
+
|
124
125
|
# check for a nest <xsl:sort element
|
125
|
-
|
126
|
+
|
126
127
|
sort = x.element('xsl:sort')
|
127
|
-
|
128
|
+
|
128
129
|
if sort then
|
129
130
|
|
130
131
|
orderx = sort.attributes[:order] || 'ascending'
|
@@ -151,50 +152,50 @@ class Rexslt
|
|
151
152
|
end
|
152
153
|
|
153
154
|
if matched_node then
|
154
|
-
|
155
|
+
|
155
156
|
template_xpath, template = raw_template
|
156
|
-
|
157
|
+
|
157
158
|
if sort_field then
|
158
|
-
|
159
|
-
sort_order = lambda do |x|
|
160
|
-
|
161
|
-
r = x.element(sort_field);
|
162
159
|
|
163
|
-
|
160
|
+
sort_order = lambda do |x|
|
161
|
+
|
162
|
+
r = x.element(sort_field);
|
163
|
+
|
164
|
+
if r.respond_to?(:value) then
|
164
165
|
r.value
|
165
166
|
else
|
166
167
|
data_type == 'text' ? r : r.to_i
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|
170
|
-
a = matched_node.sort_by(&sort_order).each_with_index do |child_node,i|
|
171
|
+
a = matched_node.sort_by(&sort_order).each_with_index do |child_node,i|
|
171
172
|
read_node template, child_node, doc_element, indent, i+1
|
172
173
|
end
|
173
174
|
a.reverse! if orderx == 'descending'
|
174
175
|
else
|
175
|
-
r = matched_node.each_with_index do |child_node,i|
|
176
|
+
r = matched_node.each_with_index do |child_node,i|
|
176
177
|
read_node template, child_node, doc_element, indent, i+1
|
177
|
-
end
|
178
|
+
end
|
178
179
|
return r
|
179
180
|
end
|
180
181
|
end
|
181
182
|
|
182
183
|
end
|
183
|
-
|
184
|
+
|
184
185
|
def match?(raw_keypath, raw_path)
|
185
186
|
return false if raw_path == ['*']
|
186
|
-
keypath = raw_keypath.split('/').reverse.take raw_path.length
|
187
|
+
keypath = raw_keypath.split('/').reverse.take raw_path.length
|
187
188
|
path = raw_path.reverse
|
188
189
|
r = path.map.with_index.select{|x,i|x == '*'}.map(&:last)
|
189
190
|
|
190
|
-
r.each do |n|
|
191
|
+
r.each do |n|
|
191
192
|
# get the relative value from path
|
192
193
|
path[n] = keypath[n]
|
193
|
-
end
|
194
|
-
|
195
|
-
keypath == path
|
194
|
+
end
|
195
|
+
|
196
|
+
keypath == path
|
196
197
|
end
|
197
|
-
|
198
|
+
|
198
199
|
def position()
|
199
200
|
@position ||= 0
|
200
201
|
end
|
@@ -214,57 +215,57 @@ class Rexslt
|
|
214
215
|
|
215
216
|
doc_element.add_attribute(name, value)
|
216
217
|
end
|
217
|
-
|
218
|
+
|
218
219
|
def xsl_call_template(element, x, doc_element, indent, i)
|
219
|
-
|
220
|
+
|
220
221
|
name = x.attributes[:name]
|
221
222
|
template = @doc_xsl.root.element("xsl:template[@name='#{name}']")
|
222
|
-
|
223
|
+
|
223
224
|
read_node template, element, doc_element, indent, i
|
224
225
|
end
|
225
226
|
|
226
227
|
def xsl_choose(element, x, doc_element, indent, i)
|
227
|
-
|
228
|
+
|
228
229
|
|
229
230
|
r = x.xpath("xsl:when").map do |xsl_node|
|
230
231
|
|
231
232
|
condition = xsl_node.attributes[:test]
|
232
233
|
|
233
|
-
if element.xpath(condition).all? then
|
234
|
-
read_raw_element(element, xsl_node.elements.first, doc_element, indent, i)
|
234
|
+
if element.xpath(condition).all? then
|
235
|
+
read_raw_element(element, xsl_node.elements.first, doc_element, indent, i)
|
235
236
|
true
|
236
237
|
else
|
237
238
|
false
|
238
239
|
end
|
239
240
|
end
|
240
|
-
|
241
|
+
|
241
242
|
unless r.any? then
|
242
243
|
otherwise = x.element("xsl:otherwise")
|
243
244
|
if otherwise then
|
244
245
|
read_node(otherwise, element, doc_element, indent)
|
245
246
|
end
|
246
|
-
end
|
247
|
+
end
|
247
248
|
|
248
249
|
end
|
249
250
|
|
250
251
|
def xsl_cdata(element, x, doc_element, indent, i)
|
251
|
-
puts ('cdata x: ' + element.inspect) if @debug
|
252
|
-
|
252
|
+
puts ('cdata x: ' + element.inspect) if @debug
|
253
|
+
|
253
254
|
new_element = Rexle::CData.new(x.value.to_s)
|
254
255
|
|
255
256
|
read_node(x, element, new_element, indent, i)
|
256
|
-
doc_element.add new_element
|
257
|
+
doc_element.add new_element
|
257
258
|
end
|
258
|
-
|
259
|
+
|
259
260
|
def xsl_comment(element, x, doc_element, indent, i)
|
260
|
-
#puts ('comment x: ' + element.inspect) if @debug
|
261
|
-
|
261
|
+
#puts ('comment x: ' + element.inspect) if @debug
|
262
|
+
|
262
263
|
new_element = Rexle::Comment.new(x.value.to_s)
|
263
264
|
|
264
265
|
read_node(x, element, new_element, indent, i)
|
265
|
-
doc_element.add new_element
|
266
|
+
doc_element.add new_element
|
266
267
|
end
|
267
|
-
|
268
|
+
|
268
269
|
def xsl_copy_of(element, x, doc_element, indent, i)
|
269
270
|
#jr251012 indent = 1 unless indent
|
270
271
|
#jr251012 indent_element(element, x, doc_element, indent, indent - 1) do
|
@@ -275,38 +276,39 @@ class Rexslt
|
|
275
276
|
#jr251012 end
|
276
277
|
|
277
278
|
end
|
278
|
-
|
279
|
+
|
279
280
|
def xsl_element(element, x, doc_element, indent, i)
|
280
|
-
|
281
|
+
|
281
282
|
indent_before(element, x, doc_element, indent + 1, i) if @indent == true
|
282
283
|
|
283
284
|
name = x.attributes[:name]
|
284
285
|
variable = name[/^\{(.*)\}$/,1]
|
285
286
|
|
286
287
|
puts 'variable: ' + variable.inspect if @debug
|
287
|
-
|
288
|
+
|
288
289
|
if variable then
|
289
290
|
name = element.element(variable)
|
290
291
|
end
|
291
292
|
|
292
293
|
new_element = Rexle::Element.new(name) # .add_text(x.value.strip)
|
293
|
-
puts 'element.text: ' + element.to_s.inspect
|
294
|
+
puts 'element.text: ' + element.to_s.inspect if @debug
|
294
295
|
new_element.text = element.text.to_s.strip
|
295
296
|
|
296
297
|
read_node(x, element, new_element, indent, i)
|
297
|
-
doc_element.add new_element
|
298
|
+
doc_element.add new_element
|
298
299
|
indent_after(element, x, doc_element, indent) if @indent == true
|
299
300
|
end
|
300
|
-
|
301
|
+
|
301
302
|
def xsl_for_each(element, x, doc_element, indent, i)
|
302
|
-
|
303
|
+
|
304
|
+
puts ('inside xsl_for_each x.children: ' + x.children.inspect).debug if @debug
|
303
305
|
xpath = x.attributes[:select]
|
304
306
|
|
305
307
|
nodes = element.xpath xpath
|
306
|
-
|
308
|
+
|
307
309
|
# check for sort
|
308
310
|
sort_node = x.element 'xsl:sort'
|
309
|
-
|
311
|
+
|
310
312
|
if sort_node then
|
311
313
|
|
312
314
|
sort_field = sort_node.attributes[:select]
|
@@ -328,33 +330,35 @@ class Rexslt
|
|
328
330
|
end
|
329
331
|
|
330
332
|
end
|
331
|
-
|
333
|
+
|
332
334
|
field = raw_order[/^\{\$(.*)\}/,1]
|
333
335
|
order = field ? @param[field] : raw_order
|
334
336
|
nodes.reverse! if order.downcase == 'descending'
|
335
337
|
end
|
336
|
-
|
338
|
+
puts ('nodes: ' + nodes.inspect).debug if @debug
|
337
339
|
nodes.each.with_index {|node, j| read_node(x, node, doc_element, indent, j+1)}
|
338
|
-
|
340
|
+
|
339
341
|
end
|
340
|
-
|
342
|
+
|
341
343
|
def xsl_if(element, x, doc_element, indent, i=0)
|
342
344
|
|
343
345
|
cond = x.attributes[:test].clone
|
344
|
-
|
346
|
+
puts ('cond: ' + cond.inspect).debug if @debug
|
347
|
+
|
345
348
|
cond.sub!(/position\(\)/, i.to_s)
|
346
349
|
cond.sub!(/</,'<')
|
347
350
|
cond.sub!(/>/,'>')
|
348
351
|
cond.sub!(/\bmod\b/,'%')
|
352
|
+
cond.gsub!(/'/,"'")
|
349
353
|
|
350
|
-
result = element.element cond
|
354
|
+
result = element.element cond
|
351
355
|
|
352
356
|
if result then
|
353
357
|
read_node x, element, doc_element, indent, i
|
354
358
|
end
|
355
359
|
|
356
360
|
end
|
357
|
-
|
361
|
+
|
358
362
|
# Ignores comment tags
|
359
363
|
#
|
360
364
|
def ignore(*args)
|
@@ -362,7 +366,7 @@ class Rexslt
|
|
362
366
|
|
363
367
|
def indent_before(element, x, doc_element, indent, i)
|
364
368
|
text = ''
|
365
|
-
unless doc_element.texts.empty? and doc_element.texts.last.nil? then
|
369
|
+
unless doc_element.texts.empty? and doc_element.texts.last.nil? then
|
366
370
|
if indent > 1 then
|
367
371
|
text = "\n" + ' ' * (indent - 1) #unless doc_element.texts.last.to_s[/^\n\s/m]
|
368
372
|
end
|
@@ -374,36 +378,37 @@ class Rexslt
|
|
374
378
|
end
|
375
379
|
|
376
380
|
def indent_after(element, x, doc_element, prev_indent)
|
377
|
-
|
381
|
+
|
378
382
|
puts 'indent? : ' + @indent.inspect if @debug
|
379
383
|
|
380
|
-
if @indent == true then
|
384
|
+
if @indent == true then
|
381
385
|
doc_element.add_text ' ' * (prev_indent > 0 ? prev_indent - 1 : prev_indent)
|
382
|
-
end
|
386
|
+
end
|
383
387
|
end
|
384
|
-
|
385
|
-
def indent_element(element, x, doc_element, indent, previous_indent)
|
386
|
-
indent_before(element, x, doc_element, indent, i) if @indent == true
|
388
|
+
|
389
|
+
def indent_element(element, x, doc_element, indent, previous_indent)
|
390
|
+
indent_before(element, x, doc_element, indent, i) if @indent == true
|
387
391
|
yield
|
388
392
|
indent_after(element, x, doc_element, previous_indent) if @indent == true
|
389
|
-
end
|
393
|
+
end
|
390
394
|
|
391
|
-
def padding(element,raw_indent, x)
|
395
|
+
def padding(element,raw_indent, x)
|
392
396
|
# if there is any other elements in doc_element don't check for an indent!!!!
|
393
397
|
|
394
|
-
indent = 0
|
395
|
-
indent = raw_indent + 1 if element.texts.length <= 0
|
396
|
-
x.to_s.strip.length > 0 ? ' ' * indent : ''
|
398
|
+
indent = 0
|
399
|
+
indent = raw_indent + 1 if element.texts.length <= 0
|
400
|
+
x.to_s.strip.length > 0 ? ' ' * indent : ''
|
397
401
|
end
|
398
|
-
|
399
|
-
|
402
|
+
|
403
|
+
|
400
404
|
# Reads an XSL node which is either an XSL element, a string or a comment
|
401
405
|
# template_node: XSL node
|
402
406
|
# element: XML node
|
403
407
|
# doc_element: target document element
|
404
408
|
#
|
405
409
|
def read_node(template_node, element, doc_element, indent, i=0)
|
406
|
-
|
410
|
+
|
411
|
+
puts 'children: ' + template_node.children.inspect if @debug
|
407
412
|
template_node.children.each_with_index do |x,j|
|
408
413
|
|
409
414
|
puts ('x: ' + x.inspect).debug if @debug
|
@@ -413,9 +418,10 @@ class Rexslt
|
|
413
418
|
else
|
414
419
|
:ignore
|
415
420
|
end
|
421
|
+
puts ('name: ' + name.inspect).debug if @debug
|
416
422
|
|
417
423
|
r2 = method(name).call(element, x, doc_element, indent, i)
|
418
|
-
puts '
|
424
|
+
puts 'r2b: ' + r2.inspect if @debug
|
419
425
|
r2
|
420
426
|
|
421
427
|
end
|
@@ -435,17 +441,18 @@ class Rexslt
|
|
435
441
|
end
|
436
442
|
|
437
443
|
end
|
438
|
-
|
444
|
+
|
439
445
|
# element: xml element
|
440
446
|
# x: xsl element
|
441
|
-
# doc_element:
|
447
|
+
# doc_element:
|
442
448
|
#
|
443
449
|
def read_raw_element(element, x, doc_element, indent, j)
|
444
|
-
|
445
|
-
method_name = x.name.gsub(/[:-]/,'_').to_sym
|
446
|
-
|
450
|
+
|
451
|
+
method_name = x.name.gsub(/[:-]/,'_').to_sym
|
452
|
+
puts ('method_name: ' + method_name.inspect).debug if @debug
|
453
|
+
|
447
454
|
if @xsl_methods.include? method_name then
|
448
|
-
|
455
|
+
|
449
456
|
if method_name == :'xsl_apply_templates' then
|
450
457
|
#doc_element = doc_element.elements.last
|
451
458
|
end
|
@@ -454,18 +461,18 @@ class Rexslt
|
|
454
461
|
|
455
462
|
else
|
456
463
|
|
457
|
-
previous_indent = indent
|
464
|
+
previous_indent = indent
|
458
465
|
la = x.name
|
459
466
|
new_indent = indent + 1 if @indent == true
|
460
467
|
|
461
468
|
new_element = x.clone
|
462
469
|
|
463
|
-
new_element.attributes.each do |k,raw_v|
|
464
|
-
|
470
|
+
new_element.attributes.each do |k,raw_v|
|
471
|
+
|
465
472
|
v = raw_v.is_a?(Array) ? raw_v.join(' ') : raw_v
|
466
|
-
|
467
|
-
puts 'v: ' + v.inspect if @debug
|
468
|
-
|
473
|
+
|
474
|
+
puts 'v: ' + v.inspect if @debug
|
475
|
+
|
469
476
|
if v[/{/] then
|
470
477
|
|
471
478
|
v.gsub!(/(\{[^\}]+\})/) do |x2|
|
@@ -475,22 +482,22 @@ class Rexslt
|
|
475
482
|
text = element.text(xpath).to_s.strip
|
476
483
|
puts 'text: ' + text.inspect if @debug
|
477
484
|
text ? text.clone : ''
|
478
|
-
|
485
|
+
|
479
486
|
end
|
480
|
-
|
487
|
+
|
481
488
|
puts '2. v: ' + v.inspect if @debug
|
482
489
|
|
483
|
-
end
|
484
|
-
end
|
490
|
+
end
|
491
|
+
end
|
485
492
|
|
486
493
|
puts 'x.children.length: ' + x.children.length.inspect if @debug
|
487
|
-
|
488
|
-
if x.children.length > 0 then
|
494
|
+
|
495
|
+
if x.children.length > 0 then
|
489
496
|
|
490
497
|
indent_before(element, x, doc_element, new_indent, j) if @indent == true
|
491
|
-
|
492
|
-
read_node(x, element, new_element, new_indent, j)
|
493
|
-
doc_element.add new_element
|
498
|
+
|
499
|
+
read_node(x, element, new_element, new_indent, j)
|
500
|
+
doc_element.add new_element
|
494
501
|
|
495
502
|
if @indent == true then
|
496
503
|
if doc_element.children.last.children.any? \
|
@@ -504,23 +511,23 @@ class Rexslt
|
|
504
511
|
else
|
505
512
|
|
506
513
|
indent_before(element, x, new_element, new_indent, j) if @indent == true
|
507
|
-
|
508
|
-
val = @indent == true ? x.to_s : x.to_s
|
514
|
+
|
515
|
+
val = @indent == true ? x.to_s : x.to_s
|
509
516
|
#jr020219 doc_element.add val
|
510
517
|
doc_element.add new_element
|
511
518
|
|
512
519
|
end
|
513
|
-
|
520
|
+
|
514
521
|
end
|
515
522
|
#new_element
|
516
523
|
#puts 'attributes: ' + new_element.attributes.inspect if @debug
|
517
|
-
|
524
|
+
|
518
525
|
end
|
519
|
-
|
526
|
+
|
520
527
|
def value_of(x, elementx, i)
|
521
|
-
|
528
|
+
|
522
529
|
puts 'value_of: ' + elementx.to_s.inspect if @debug
|
523
|
-
|
530
|
+
|
524
531
|
field = x.attributes[:select]
|
525
532
|
|
526
533
|
o = case field
|
@@ -541,36 +548,39 @@ class Rexslt
|
|
541
548
|
end
|
542
549
|
|
543
550
|
end
|
544
|
-
|
551
|
+
|
545
552
|
end
|
546
|
-
|
553
|
+
|
547
554
|
def xsl_output()
|
548
555
|
|
549
556
|
end
|
550
|
-
|
557
|
+
|
551
558
|
def xsl_text(element, x, doc_element, indent, i)
|
552
559
|
|
553
|
-
|
554
|
-
|
560
|
+
puts ('inside xsl_text x.value:' + x.inspect).debug if @debug
|
561
|
+
val = @indent == true ? padding(doc_element, indent, x) : ''
|
562
|
+
|
555
563
|
val += if x.attributes[:"disable-output-escaping"] then
|
556
564
|
x.value.unescape
|
557
565
|
else
|
558
566
|
x.value.to_s
|
559
567
|
end
|
560
|
-
|
568
|
+
|
561
569
|
doc_element.add_element val
|
562
|
-
|
570
|
+
|
563
571
|
end
|
564
|
-
|
572
|
+
|
565
573
|
def xsl_value_of(element, x, doc_element, indent, i)
|
566
|
-
|
574
|
+
|
567
575
|
#puts 'xsl_value_of: ' + x.inspect if @debug
|
568
576
|
s = value_of(x, element,i)
|
577
|
+
puts ('xsl_value_of s: ' + s.inspect).debug if @debug
|
578
|
+
|
569
579
|
doc_element.add_text s
|
570
580
|
doc_element
|
571
|
-
|
581
|
+
|
572
582
|
end
|
573
|
-
|
583
|
+
|
574
584
|
|
575
585
|
def xslt_transform(raw_xsl, xml, custom_params={})
|
576
586
|
|
@@ -580,7 +590,7 @@ class Rexslt
|
|
580
590
|
|
581
591
|
@doc_xsl = raw_xsl.is_a?(Rexle) ? raw_xsl : Rexle.new(raw_xsl.gsub(/(?<=\<\/xsl:text>)[^<]+/,''))
|
582
592
|
puts 'after @doc_xsl'.info if @debug
|
583
|
-
|
593
|
+
|
584
594
|
#jr2040516 filter_out_spaces @doc_xsl.root
|
585
595
|
|
586
596
|
@doc = Rexle.new '<root4></root4>', debug: @debug
|
@@ -589,10 +599,10 @@ class Rexslt
|
|
589
599
|
|
590
600
|
previous_indent = 0
|
591
601
|
@xsl_methods = %i(apply_templates value_of element if choose when copy_of
|
592
|
-
attribute for_each text output call_template comment cdata).map do |x|
|
602
|
+
attribute for_each text output call_template comment cdata).map do |x|
|
593
603
|
('xsl_' + x.to_s).to_sym
|
594
604
|
end
|
595
|
-
|
605
|
+
|
596
606
|
strip_space = @doc_xsl.root.element "xsl:strip-space/attribute::elements"
|
597
607
|
|
598
608
|
if strip_space then
|
@@ -601,25 +611,25 @@ class Rexslt
|
|
601
611
|
nodes = doc_xml.root.xpath "//" + element + "[text()]"
|
602
612
|
a = nodes.select {|x| x.value.to_s.strip.empty?}
|
603
613
|
a.each {|node| node.parent.delete node}
|
604
|
-
end
|
614
|
+
end
|
605
615
|
end
|
606
616
|
|
607
617
|
h = @doc_xsl.root.element("xsl:output/attribute::*")
|
608
618
|
puts 'h: ' + h.inspect if @debug
|
609
619
|
puts 'after h'.info if @debug
|
610
|
-
|
620
|
+
|
611
621
|
if h and ((h[:method] and h[:method].downcase == 'html') \
|
612
622
|
or h[:'omit-xml-declaration'] == 'yes') then
|
613
|
-
@options[:declaration] = :none
|
623
|
+
@options[:declaration] = :none
|
614
624
|
end
|
615
625
|
|
616
626
|
@indent = (h and h[:indent] == 'yes') ? true : false
|
617
|
-
|
627
|
+
|
618
628
|
params = @doc_xsl.root.xpath("xsl:param").map{|x| [x.attributes[:name], x.value]}
|
619
629
|
@param = Hash[params].merge(custom_params) if params
|
620
630
|
# search for params
|
621
|
-
|
622
|
-
|
631
|
+
|
632
|
+
|
623
633
|
# fetch the templates
|
624
634
|
#puts "Rexle:Version: " + Rexle.version
|
625
635
|
|
@@ -627,36 +637,36 @@ class Rexslt
|
|
627
637
|
r.merge(x.attributes[:match] || x.attributes[:select] => x)
|
628
638
|
end
|
629
639
|
|
630
|
-
# using the 1st template
|
640
|
+
# using the 1st template
|
631
641
|
xpath = String.new @templates.to_a[0][0]
|
632
642
|
out = read_node(@templates.to_a[0][-1], doc_xml.element(xpath), @doc.root, indent)
|
633
643
|
|
634
644
|
puts ('out: ' + out.inspect).debug if @debug
|
635
|
-
|
645
|
+
|
636
646
|
html = @doc.root.element('html')
|
637
|
-
|
647
|
+
|
638
648
|
if html then
|
639
|
-
|
649
|
+
|
640
650
|
if h and h[:'omit-xml-declaration'] != 'yes' then
|
641
651
|
else
|
642
652
|
@options[:declaration] = :none
|
643
653
|
end
|
644
|
-
|
645
|
-
end
|
654
|
+
|
655
|
+
end
|
646
656
|
|
647
657
|
if @doc_xsl.root.element('xsl:output[@method="html"]') or html then
|
648
|
-
|
658
|
+
|
649
659
|
head = @doc.root.element('html/head')
|
650
660
|
|
651
661
|
if head and not head.element('meta[@content]') then
|
652
|
-
|
662
|
+
|
653
663
|
h = {
|
654
|
-
:'http-equiv' => "Content-Type",
|
664
|
+
:'http-equiv' => "Content-Type",
|
655
665
|
content: 'text/html; charset=utf-8'
|
656
666
|
}
|
657
667
|
meta_element = Rexle::Element.new('meta', attributes: h)
|
658
668
|
child = head.element('*')
|
659
|
-
|
669
|
+
|
660
670
|
if child then
|
661
671
|
child.insert_before meta_element
|
662
672
|
else
|
@@ -664,8 +674,8 @@ class Rexslt
|
|
664
674
|
end
|
665
675
|
|
666
676
|
end
|
667
|
-
end
|
668
|
-
|
677
|
+
end
|
678
|
+
|
669
679
|
out
|
670
680
|
|
671
681
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexslt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,74 +11,74 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjIyMjEwNTU4WhcN
|
15
|
+
MjMwMjIyMjEwNTU4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCviJpV
|
17
|
+
7BhQrIEJAPtUTpf+Nh18gFdZkplX/lhlyYgy+79+RZ3KH3T9a7aY/SZVDbtNWiY4
|
18
|
+
oeN7TEykNteUZGqoVHTr/hqeZCAvqj6CzSuzu/pbXeEguHjaaoOvfSq+AYqgxn7E
|
19
|
+
rU5x+BP6B3GspeNah8acqoxdHexQr3FLpK8mHSj8AA8HYEnfpkkRadjRwYh1KeYP
|
20
|
+
9jTtTCQTnQAGYXzyVpByNaq/jPdx9An5jKmPGwp+GdfsgDseuf66DCeEmW9em8t+
|
21
|
+
Q8//+kkta0gqJrBi8jfHTbvPLGjRJvZBNfyrkR8XWeIvPaoNWL/YgBUF72jaW0EO
|
22
|
+
TAWT5KpeQu3gKJ0B7ZWMBWHl2WpFAqKKVTYYHaNoXwXAwhLyb3f09PpKv46PAxVB
|
23
|
+
8OeKHdBnlFusIJIgQcJy/2BBsgvmfxxDejAIWTGvU36rn1sZI9GXmOFq1xdRyAJL
|
24
|
+
5WDPlayTuyUwIwTE8paeurStLIy2I5Gj7YroWxVC8JfvZmr17C0afJ+i69UCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUZjuOOaGG
|
26
|
+
kzWNN4chlNUr7YC84yAwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
27
|
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
/
|
36
|
-
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAYqfppNhIGkd0ClxF0U7BKFLXyt0JuP+z3vdduaFE
|
29
|
+
7a0xpm37qPNvuz+Ww2nsDunT2IEzmQG9fXBBLPRQ+6O96HijwnXf2syxu0RqsdHx
|
30
|
+
MpS6kjfT1UtItWqkfbPnMc0xjt9WGN3uMHD/Oyd5YlkpavjYVg0SkER+KD9IOSZJ
|
31
|
+
hO1WdIMovS4+IEYp8GwJ8d45o+qsRBbz/CE8kw/h2umwycPpOZBWGKSzGPVfitw9
|
32
|
+
+NHdqE7IPeO0TawyI8J5s2pLrdAGTr37H7hyV3d3aCkbdjja/PImVZnzRGNtUM3D
|
33
|
+
V7JeTyQuA/Mm4oKVIo/2Ek9zgJ769bxMt7Ind7GoxEpvw0yzdJDHRJWchUDxUzpa
|
34
|
+
s1EwGaedPdVKqZGZ5b6jPn7my/oy6tSsZ3fxeS5hGOC9krHfNfI0hOQSdnEYRQ7V
|
35
|
+
T15IZrtCCsr4cegFYA/pTPKa6zXILl0jjrHxngeeQgbzyhqzwV512tPs1tS+BGte
|
36
|
+
qFkZFEE756UeJHNHxPHZgsyk
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: rxfreader
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.0.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
46
|
+
version: '0.2'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.2.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.0.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
56
|
+
version: '0.2'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.2.1
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rexle
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '1.
|
66
|
+
version: '1.5'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
69
|
+
version: 1.5.14
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '1.
|
76
|
+
version: '1.5'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.
|
79
|
+
version: 1.5.14
|
80
80
|
description:
|
81
|
-
email:
|
81
|
+
email: digital.robertson@gmail.com
|
82
82
|
executables: []
|
83
83
|
extensions: []
|
84
84
|
extra_rdoc_files: []
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.2.22
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Rexslt is an XSLT processor written purely in Ruby
|
metadata.gz.sig
CHANGED
Binary file
|