rexslt 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rexslt.rb +14 -10
- metadata +1 -1
data/lib/rexslt.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# file: rexslt.rb
|
4
|
-
|
5
1
|
require 'rexml/document'
|
6
2
|
|
7
3
|
class Rexslt
|
@@ -12,6 +8,8 @@ class Rexslt
|
|
12
8
|
doc_xml = Document.new(xml)
|
13
9
|
doc_xsl = Document.new(xsl)
|
14
10
|
|
11
|
+
@xsl_methods = [:apply_templates, :value_of]
|
12
|
+
|
15
13
|
# fetch the templates
|
16
14
|
@templates = XPath.match(doc_xsl.root, 'xsl:template').inject({}) do |r,x|
|
17
15
|
r.merge(x.attribute('match').value => x)
|
@@ -24,9 +22,9 @@ class Rexslt
|
|
24
22
|
|
25
23
|
end
|
26
24
|
|
27
|
-
def to_s()
|
28
|
-
|
29
|
-
end
|
25
|
+
def to_s() @a.flatten.join end
|
26
|
+
|
27
|
+
def to_a() @a end
|
30
28
|
|
31
29
|
alias text to_s
|
32
30
|
|
@@ -34,10 +32,16 @@ class Rexslt
|
|
34
32
|
|
35
33
|
def read_template(template_node, doc_node)
|
36
34
|
|
37
|
-
XPath.match(template_node, '*').map do |x|
|
35
|
+
XPath.match(template_node, '*').map do |x|
|
36
|
+
|
38
37
|
method_name = x.name.gsub(/-/,'_').to_sym
|
39
|
-
|
40
|
-
|
38
|
+
|
39
|
+
if @xsl_methods.include? method_name then
|
40
|
+
field = x.attribute('select').value.to_s if x.attribute('select')
|
41
|
+
method(method_name).call(doc_node, field)
|
42
|
+
else
|
43
|
+
x.to_s
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|