xml_to_xsl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +3 -0
- data/lib/xml_to_xsl.rb +113 -0
- metadata +67 -0
- metadata.gz.sig +2 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e733075d76910d6d4d4b1ed87fa772338a9df329
|
4
|
+
data.tar.gz: 4e7632e822f5afdf25275fcb4e5f745d27e31121
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e0f55ceacd0179a0f3a8469deab34e474f0d5c7748cbd348685a5172441bb4ff4a84b414372f88bace745061109da06b5db693f5cc4d62c174e06844b121c3a
|
7
|
+
data.tar.gz: c63c1d0d56604208a029db3bf800b4e0b6ef4fa5b02e7d24f91eee77d3b4e2e9fdc563bfc044d27c48ff98426ce95f4e58cf999edc7b71e46f9130220a005a45
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ury��1Ӕ58����9HLDa5W(���w�)|��= &,��S���wR�������͒�����]�#� p4x��к�5U��$�@G`��t�A^��gW~���+������2ih\�HuD���W#���S��Σ�{PbV���ƭ�����~��@�A���������q���'f�x|�i��$.&�������Y�hI1}ͥV�%aY���#=L/971��t��
|
data.tar.gz.sig
ADDED
data/lib/xml_to_xsl.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: xml_to_xsl.rb
|
4
|
+
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
class XMLToXSL
|
10
|
+
|
11
|
+
include REXML
|
12
|
+
|
13
|
+
attr_reader :to_xsl
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(xml)
|
17
|
+
|
18
|
+
doc = Document.new(xml)
|
19
|
+
|
20
|
+
|
21
|
+
@to_xsl = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"\
|
22
|
+
" version='1.0'>
|
23
|
+
|
24
|
+
<xsl:template match='#{doc.root.name}'>
|
25
|
+
|
26
|
+
<xsl:element name='#{doc.root.name}'>
|
27
|
+
#{write_attributes(doc.root.attributes).join("\n")}
|
28
|
+
#{build_xml(doc.root)}
|
29
|
+
</xsl:element>
|
30
|
+
|
31
|
+
</xsl:template>
|
32
|
+
|
33
|
+
</xsl:stylesheet>"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
|
41
|
+
def build_xml(node)
|
42
|
+
|
43
|
+
r = []
|
44
|
+
|
45
|
+
previous_name = ''
|
46
|
+
|
47
|
+
|
48
|
+
node.elements.each do |child|
|
49
|
+
|
50
|
+
|
51
|
+
if child.length > 1
|
52
|
+
|
53
|
+
r << build_template(child)
|
54
|
+
|
55
|
+
r << build_xml(child)
|
56
|
+
|
57
|
+
else
|
58
|
+
|
59
|
+
r << build_value(child,node) if child.name != previous_name
|
60
|
+
|
61
|
+
previous_name = child.name
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
r.join
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
def build_template(element)
|
73
|
+
|
74
|
+
"<xsl:apply-templates select='#{element.name}' />
|
75
|
+
</xsl:element>
|
76
|
+
|
77
|
+
</xsl:template>
|
78
|
+
|
79
|
+
<xsl:template match='#{element.name}'>"
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def build_value(element,parent)
|
86
|
+
|
87
|
+
|
88
|
+
"\n
|
89
|
+
<xsl:element name='#{parent.name}'>
|
90
|
+
#{write_attributes(parent.attributes).join("\n")}
|
91
|
+
<xsl:apply-templates select='#{element.name}' />
|
92
|
+
</xsl:element>
|
93
|
+
|
94
|
+
</xsl:template>
|
95
|
+
|
96
|
+
<xsl:template match='#{element.name}'>
|
97
|
+
|
98
|
+
<xsl:element name='#{element.name}'>
|
99
|
+
#{write_attributes(element.attributes).join("\n")}
|
100
|
+
<xsl:value-of select='.' />"
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def write_attributes(attr)
|
106
|
+
attr.map do |key, val|
|
107
|
+
" <xsl:attribute name='#{key}'>
|
108
|
+
<xsl:value-of select='@#{key}'/>
|
109
|
+
</xsl:attribute>"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xml_to_xsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE0MDkxNzIwMjYwN1oXDTE1MDkxNzIwMjYwN1owSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBANI0WbtPK7pWlODYkWAK0BmJTQCzq2APhTkO5RfN75z4jaFMMacwVZ3s0IMz
|
19
|
+
ss5g0AWzYhAbKrMSb6atlAINbgssekWWyeLnxtHb9OyhMT4yryb/jV/dY0+MmRof
|
20
|
+
jj6kimX8vxg5WxPdYYTIaxrAh/tI1J3mSGBupTtocn24AaTQ6fY6eVcsCTXHhm/o
|
21
|
+
d2j1c1hBKkr7R4lm0LKrVkhkf+wRcIha4KPz1Al5jsq72zGBiTNzl5P7F1BMAHt4
|
22
|
+
fLct6e+/7XNl+Ft1CQmbeCCdXiCt8hMTXHF2ozQKadF83zLNN/6owadJnYmpryl1
|
23
|
+
aSOEWrGj5GlOgNnou8MKsq7e/V8CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUAAPV9QKaoXDepUyKiVh3bd1iO9gwJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAdOYdRIyg
|
27
|
+
4jl12Gl4aPqenqORQkXa1hD3oqNEsl4uOfHmgdhim4sdPuKzs11RJnYgDHg4P+5l
|
28
|
+
ptJ+9872QhJGMHo8NmADVGusLv9GyjV0W+xZ0wPNfwBJf6tY0342qBXWchRXo4yz
|
29
|
+
UzDyChMWRNejpCKzFa1YZke0AhH1QTj5LXQNs2wkm60m1ps6k5hdUgBwJo4xvebb
|
30
|
+
pwzb2mM1Qt529cQZjq49jHItKNBIXRuPrVxe2A0+DqkOliypFRaWU8FpujJYRHr2
|
31
|
+
L6w0p6K3ILUyF6WStr1WXcL2I4RCJr6Xilc+Z8dS4p++gQxRlZzh8bi8qpfSFKw4
|
32
|
+
E8XbyB70CK1sgw==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
35
|
+
dependencies: []
|
36
|
+
description:
|
37
|
+
email: james@r0bertson.co.uk
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/xml_to_xsl.rb
|
43
|
+
homepage: https://github.com/jrobertson/xml_to_xsl
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.2.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Creates XSLT from XML
|
67
|
+
test_files: []
|
metadata.gz.sig
ADDED