rexslt 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/rexslt.rb +91 -31
  5. metadata +37 -34
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 69797514b98a7984bc4175670b6ffc7d7863557e
4
- data.tar.gz: d62aa717f191ad2bc16998f7c388f668e6853e96
2
+ SHA256:
3
+ metadata.gz: aa90a309932376c100cce5be8f22d80a557b991f5fed84916eb7835c30bfd0a7
4
+ data.tar.gz: 41ad2d628a4c98d16a2d088b00dacb865c0935e1d57d0fde72f92a14860c45cf
5
5
  SHA512:
6
- metadata.gz: 7efcdd6aad9ff17aac7e7aa98273161cd5c5df715e7ac0ca5c7e49b7e63149d9c449f1849329de7c2d39173429b90762adacc2e548f721f726430ce016de353a
7
- data.tar.gz: 94d967daded356dedf56eeb4b59b8c8a424eaf293de2d96f8fce0395b64d65cce2415b59be4f1c67694dcc87c59fcefc40b153f6607814ad8a5c2e92cf037490
6
+ metadata.gz: 3b74db7015db32fd1f917974f499fe5542590ab7063fe0611e60969b085aa4a7710f0afcd892044958afe66f70a172d0fbcb8e1c25ba3b64330f948583b2dcc6
7
+ data.tar.gz: 14265ce7768530af39b2a6576d16c220008a12550cac838aa38ba4d3f16a4a044b5765719ae1657c12c1c004b1b0b06b6aa9e01ee95f602f83736595041f90fa
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,10 +4,15 @@
4
4
 
5
5
  require 'rexle'
6
6
  require 'rxfhelper'
7
+ require 'logger'
7
8
 
8
9
 
9
10
  # modifications:
10
-
11
+ #
12
+ # 01-Feb-2019: bug fix: new line characters are no longer stripped
13
+ # between XSL elements
14
+ # bug fix: An attribute variable value is now returned correctly
15
+ # 19-Jan-2018: feature: Implemented Rexslt#to_xml which returns pretty XML
11
16
  # 16-Sep-2017: improvement: all predicates in an xsl:choose
12
17
  # condition now must be true
13
18
  # 15-Sep-2017: feature: Implemented xsl_call_template
@@ -57,31 +62,36 @@ end
57
62
 
58
63
  class Rexslt
59
64
  using RexPath
65
+ using ColouredText
60
66
 
61
- def initialize(xsl, xml, params={})
67
+ def initialize(xsl, xml, raw_params={}, debug: false)
62
68
 
63
69
  ## debugging variables
64
70
 
65
- @log = Logger.new 'rxsl.log','daily'
66
71
  @rn = 0
67
72
  @rre = 0
68
73
 
69
74
  super()
70
- @log.debug 'before options'
75
+ puts 'before options'.info if @debug
71
76
  @options = {}
77
+
78
+ params = raw_params.merge({debug: false})
79
+ @debug = debug
72
80
  custom_params = params.inject({}){|r,x| r.merge(Hash[x[0].to_s,x[1]])}
73
- @log.debug 'before xsl_transform'
81
+ puts 'before xsl_transform'.info if @debug
74
82
 
75
83
  xslt_transform(*[xsl, xml].map{|x| RXFHelper.read(x).first}, custom_params)
76
84
  end
77
85
 
78
86
  def to_s(options={})
79
- @doc.to_s(@options.merge(options)).sub('<root>','').sub(/<\/root>$/m,'')
87
+ @doc.to_s(@options.merge(options)).sub(/<root4>/,'').sub(/<\/root4>$/m,'').lstrip
80
88
  end
81
89
 
82
90
  def to_doc(); @doc; end
83
91
 
84
- alias to_xml to_s
92
+ def to_xml()
93
+ @doc.root.xml(pretty: true).sub(/<root4>/,'').sub(/<\/root4>$/m,'')
94
+ end
85
95
 
86
96
  private
87
97
 
@@ -236,6 +246,24 @@ class Rexslt
236
246
  end
237
247
 
238
248
  end
249
+
250
+ def xsl_cdata(element, x, doc_element, indent, i)
251
+ puts ('cdata x: ' + element.inspect) if @debug
252
+
253
+ new_element = Rexle::CData.new(x.value.to_s)
254
+
255
+ read_node(x, element, new_element, indent, i)
256
+ doc_element.add new_element
257
+ end
258
+
259
+ def xsl_comment(element, x, doc_element, indent, i)
260
+ #puts ('comment x: ' + element.inspect) if @debug
261
+
262
+ new_element = Rexle::Comment.new(x.value.to_s)
263
+
264
+ read_node(x, element, new_element, indent, i)
265
+ doc_element.add new_element
266
+ end
239
267
 
240
268
  def xsl_copy_of(element, x, doc_element, indent, i)
241
269
  #jr251012 indent = 1 unless indent
@@ -255,12 +283,15 @@ class Rexslt
255
283
  name = x.attributes[:name]
256
284
  variable = name[/^\{(.*)\}$/,1]
257
285
 
286
+ puts 'variable: ' + variable.inspect if @debug
287
+
258
288
  if variable then
259
289
  name = element.element(variable)
260
290
  end
261
291
 
262
292
  new_element = Rexle::Element.new(name) # .add_text(x.value.strip)
263
- new_element.text = element.text if element.text
293
+ puts 'element.text: ' + element.to_s.inspect
294
+ new_element.text = element.text.to_s.strip
264
295
 
265
296
  read_node(x, element, new_element, indent, i)
266
297
  doc_element.add new_element
@@ -343,9 +374,11 @@ class Rexslt
343
374
  end
344
375
 
345
376
  def indent_after(element, x, doc_element, prev_indent)
377
+
378
+ puts 'indent? : ' + @indent.inspect if @debug
346
379
 
347
380
  if @indent == true then
348
- doc_element.add_text "\n" + ' ' * (prev_indent > 0 ? prev_indent - 1 : prev_indent)
381
+ doc_element.add_text ' ' * (prev_indent > 0 ? prev_indent - 1 : prev_indent)
349
382
  end
350
383
  end
351
384
 
@@ -373,6 +406,7 @@ class Rexslt
373
406
 
374
407
  template_node.children.each_with_index do |x,j|
375
408
 
409
+ puts ('x: ' + x.inspect).debug if @debug
376
410
  name = if x.kind_of? Rexle::Element then :read_raw_element
377
411
  elsif x.is_a? String then :read_raw_text
378
412
  elsif x.class.to_s =~ /Rexle::Comment$/ then :ignore
@@ -380,7 +414,10 @@ class Rexslt
380
414
  :ignore
381
415
  end
382
416
 
383
- method(name).call(element, x, doc_element, indent, i)
417
+ r2 = method(name).call(element, x, doc_element, indent, i)
418
+ puts 'r2: ' + r2.inspect if @debug
419
+ r2
420
+
384
421
  end
385
422
 
386
423
  end
@@ -393,11 +430,10 @@ class Rexslt
393
430
  if x.to_s.strip.length > 0 then
394
431
 
395
432
  val = x.to_s.strip #
396
- doc_element.add_element val
433
+ puts ('val: ' + val.inspect).debug if @debug
434
+ doc_element.add_element x.to_s
397
435
  end
398
436
 
399
- #doc_element.add_text x if x.is_a? String
400
-
401
437
  end
402
438
 
403
439
  # element: xml element
@@ -427,20 +463,28 @@ class Rexslt
427
463
  new_element.attributes.each do |k,raw_v|
428
464
 
429
465
  v = raw_v.is_a?(Array) ? raw_v.join(' ') : raw_v
430
-
466
+
467
+ puts 'v: ' + v.inspect if @debug
468
+
431
469
  if v[/{/] then
432
470
 
433
471
  v.gsub!(/(\{[^\}]+\})/) do |x2|
434
472
 
435
473
  xpath = x2[/\{([^\}]+)\}/,1]
436
- text = element.text(xpath)
474
+ puts 'element.text(xpath): ' + element.text(xpath).inspect if @debug
475
+ text = element.text(xpath).to_s.strip
476
+ puts 'text: ' + text.inspect if @debug
437
477
  text ? text.clone : ''
438
478
 
439
479
  end
480
+
481
+ puts '2. v: ' + v.inspect if @debug
440
482
 
441
483
  end
442
484
  end
443
-
485
+
486
+ puts 'x.children.length: ' + x.children.length.inspect if @debug
487
+
444
488
  if x.children.length > 0 then
445
489
 
446
490
  indent_before(element, x, doc_element, new_indent, j) if @indent == true
@@ -459,31 +503,43 @@ class Rexslt
459
503
 
460
504
  else
461
505
 
462
- indent_before(element, x, doc_element, new_indent, j) if @indent == true
506
+ indent_before(element, x, new_element, new_indent, j) if @indent == true
463
507
 
464
508
  val = @indent == true ? x.to_s : x.to_s
465
- doc_element.add val
509
+ #jr020219 doc_element.add val
510
+ doc_element.add new_element
466
511
 
467
512
  end
468
-
513
+
469
514
  end
515
+ #new_element
516
+ #puts 'attributes: ' + new_element.attributes.inspect if @debug
470
517
 
471
518
  end
472
519
 
473
- def value_of(x, element, i)
520
+ def value_of(x, elementx, i)
521
+
522
+ puts 'value_of: ' + elementx.to_s.inspect if @debug
474
523
 
475
524
  field = x.attributes[:select]
476
525
 
477
526
  o = case field
478
527
  when '.'
479
- element.value
528
+ elementx.value
480
529
  when /^\$/
481
530
  @param[field[/^\$(.*)/,1]]
482
531
  when 'position()'
483
532
  i.to_s
484
533
  else
485
- ee = element.text(field)
486
- ee
534
+ r = elementx.element(field)
535
+ if r.is_a? Rexle::Element::Attribute
536
+ r.value.to_s
537
+ elsif r.is_a? Rexle::Element
538
+ r.texts.join
539
+ else
540
+ ''
541
+ end
542
+
487
543
  end
488
544
 
489
545
  end
@@ -507,7 +563,8 @@ class Rexslt
507
563
  end
508
564
 
509
565
  def xsl_value_of(element, x, doc_element, indent, i)
510
-
566
+
567
+ #puts 'xsl_value_of: ' + x.inspect if @debug
511
568
  s = value_of(x, element,i)
512
569
  doc_element.add_text s
513
570
  doc_element
@@ -517,22 +574,22 @@ class Rexslt
517
574
 
518
575
  def xslt_transform(raw_xsl, xml, custom_params={})
519
576
 
520
- @log.debug 'inside xslt_transform'
577
+ puts 'inside xslt_transform'.info if @debug
521
578
 
522
579
  doc_xml = xml.is_a?(Rexle) ? xml : Rexle.new(xml)
523
580
 
524
- @doc_xsl = raw_xsl.is_a?(Rexle) ? raw_xsl : Rexle.new(raw_xsl)
525
- @log.debug 'after @doc_xsl'
581
+ @doc_xsl = raw_xsl.is_a?(Rexle) ? raw_xsl : Rexle.new(raw_xsl.gsub(/(?<=\<\/xsl:text>)[^<]+/,''))
582
+ puts 'after @doc_xsl'.info if @debug
526
583
 
527
584
  #jr2040516 filter_out_spaces @doc_xsl.root
528
585
 
529
- @doc = Rexle.new '<root></root>'
586
+ @doc = Rexle.new '<root4></root4>', debug: @debug
530
587
 
531
588
  indent = 0
532
589
 
533
590
  previous_indent = 0
534
591
  @xsl_methods = %i(apply_templates value_of element if choose when copy_of
535
- attribute for_each text output call_template).map do |x|
592
+ attribute for_each text output call_template comment cdata).map do |x|
536
593
  ('xsl_' + x.to_s).to_sym
537
594
  end
538
595
 
@@ -548,7 +605,8 @@ class Rexslt
548
605
  end
549
606
 
550
607
  h = @doc_xsl.root.element("xsl:output/attribute::*")
551
- @log.debug 'after h'
608
+ puts 'h: ' + h.inspect if @debug
609
+ puts 'after h'.info if @debug
552
610
 
553
611
  if h and ((h[:method] and h[:method].downcase == 'html') \
554
612
  or h[:'omit-xml-declaration'] == 'yes') then
@@ -572,6 +630,8 @@ class Rexslt
572
630
  # using the 1st template
573
631
  xpath = String.new @templates.to_a[0][0]
574
632
  out = read_node(@templates.to_a[0][-1], doc_xml.element(xpath), @doc.root, indent)
633
+
634
+ puts ('out: ' + out.inspect).debug if @debug
575
635
 
576
636
  html = @doc.root.element('html')
577
637
 
@@ -610,4 +670,4 @@ class Rexslt
610
670
 
611
671
  end
612
672
 
613
- end
673
+ end
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.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,49 +10,53 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE3MDkxNTIwMjQwM1oXDTE4MDkxNTIwMjQwM1owSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAMlR9HT3XszqknU82ijbs8uTs91F9jkc+2oXFCmTDwx7K6RIsUYs4J5p2hnw
19
- Rg3JMpgbCnlz2/bOenXHYq2+MYw5jql68lorwqAvPOSqgnmgolid5EuNNyGqlDHB
20
- Mkp79B2ZhNO8Gz77ruYgCKVkGCrwO2Njc8iGGnEiRUAntRna1YcFNYKOU1hllqDI
21
- oKn0efB/Y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a39WWZ
33
+ ESidVaVw58zW50BejA4CitkgPe40gAYUbWLbl/JmaPEY7BusUghRxP0yE0SCTUPZ
34
+ Kd+1svoJytUIfwSCQoVgapdhxx6Z1sz9IeGswNCHPaP/jebMXJIL+PYU/7AHTRXu
35
+ /16J2OUcKrvQrokVNgm0rF4M9Hu4NBscxtnDWItY6latWceUQ8Er0p4Sgd2l5AGY
36
+ CeLdjbFCkrm/RzoszCPvxQcQ
33
37
  -----END CERTIFICATE-----
34
- date: 2017-09-16 00:00:00.000000000 Z
38
+ date: 2020-06-11 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: rxfhelper
38
42
  requirement: !ruby/object:Gem::Requirement
39
43
  requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '0.4'
43
44
  - - ">="
44
45
  - !ruby/object:Gem::Version
45
- version: 0.4.2
46
+ version: 1.0.0
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '0.4'
53
54
  - - ">="
54
55
  - !ruby/object:Gem::Version
55
- version: 0.4.2
56
+ version: 1.0.0
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: rexle
58
62
  requirement: !ruby/object:Gem::Requirement
@@ -62,7 +66,7 @@ dependencies:
62
66
  version: '1.4'
63
67
  - - ">="
64
68
  - !ruby/object:Gem::Version
65
- version: 1.4.9
69
+ version: 1.4.12
66
70
  type: :runtime
67
71
  prerelease: false
68
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,7 +76,7 @@ dependencies:
72
76
  version: '1.4'
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: 1.4.9
79
+ version: 1.4.12
76
80
  description:
77
81
  email: james@jamesrobertson.eu
78
82
  executables: []
@@ -99,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
103
  - !ruby/object:Gem::Version
100
104
  version: '0'
101
105
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.8
106
+ rubygems_version: 3.0.3
104
107
  signing_key:
105
108
  specification_version: 4
106
109
  summary: Rexslt is an XSLT processor written purely in Ruby
metadata.gz.sig CHANGED
Binary file