geo_combine 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ <!--
2
+
3
+ strip-digits.xsl
4
+
5
+ Author: John Maurer (jmaurer@hawaii.edu)
6
+ Date: November 18, 2011
7
+
8
+ This Extensible Stylesheet Language for Transformations (XSLT) document takes
9
+ a number and outputs it with up to the specified number of digits following the
10
+ decimal point. If there are fewer than the specified number of digits, all will
11
+ be returned and no extra. If there are no decimal places, the supplied integer
12
+ will be returned unchanged. Looks for exponent segment in number string
13
+ (e.g. 1.0045E-4) and maintains that if present.
14
+
15
+ You can import this XSLT in other XSLT files to call the "strip-digits" template
16
+ for accomplishing this. Here is an example import statement:
17
+
18
+ <xsl:import href="strip-digits.xsl"/>
19
+
20
+ For more information on XSLT see:
21
+
22
+ http://en.wikipedia.org/wiki/XSLT
23
+ http://www.w3.org/TR/xslt
24
+
25
+ -->
26
+
27
+ <xsl:stylesheet
28
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29
+ version="1.0">
30
+
31
+ <xsl:template name="strip-digits">
32
+ <xsl:param name="element"/>
33
+ <xsl:param name="num-digits"/>
34
+ <xsl:choose>
35
+ <xsl:when test="contains( $element, '.' )">
36
+ <xsl:variable name="element-uc" select="translate( $element, 'e', 'E' )"/>
37
+ <xsl:choose>
38
+ <xsl:when test="contains( $element-uc, 'E' )">
39
+ <xsl:variable name="before-exponent" select="substring-before( $element-uc, 'E' )"/>
40
+ <xsl:variable name="exponent" select="substring-after( $element-uc, 'E' )"/>
41
+ <xsl:variable name="before-decimal" select="substring-before( $before-exponent, '.' )"/>
42
+ <xsl:variable name="after-decimal" select="substring-after( $before-exponent, '.' )"/>
43
+ <xsl:variable name="after-decimal-stripped" select="substring( $after-decimal, 1, $num-digits )"/>
44
+ <xsl:value-of select="concat( $before-decimal, '.', $after-decimal-stripped, 'E', $exponent )"/>
45
+ </xsl:when>
46
+ <xsl:otherwise>
47
+ <xsl:variable name="before-decimal" select="substring-before( $element, '.' )"/>
48
+ <xsl:variable name="after-decimal" select="substring-after( $element, '.' )"/>
49
+ <xsl:variable name="after-decimal-stripped" select="substring( $after-decimal, 1, $num-digits )"/>
50
+ <xsl:value-of select="concat( $before-decimal, '.', $after-decimal-stripped )"/>
51
+ </xsl:otherwise>
52
+ </xsl:choose>
53
+ </xsl:when>
54
+ <xsl:otherwise>
55
+ <xsl:value-of select="$element"/>
56
+ </xsl:otherwise>
57
+ </xsl:choose>
58
+ </xsl:template>
59
+
60
+ </xsl:stylesheet>
@@ -0,0 +1,87 @@
1
+ <xsl:stylesheet
2
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
+ version="1.0">
4
+
5
+ <xsl:template name="url-decode">
6
+
7
+ <xsl:param name="in" as="xs:string"/>
8
+ <xsl:param name="seq" as="xs:string*"/>
9
+
10
+ <xsl:variable name="unreserved" as="xs:integer+"
11
+ select="(45, 46, 48 to 57, 65 to 90, 95, 97 to 122, 126)"/>
12
+
13
+ <xsl:choose>
14
+ <xsl:when test="not($in)">
15
+ <xsl:sequence select="string-join($seq, '')"/>
16
+ </xsl:when>
17
+ <xsl:when test="starts-with($in, '%')">
18
+ <xsl:choose>
19
+ <xsl:when test="matches(substring($in, 2, 2), '^[0-9A-Fa-f][0-9A-Fa-f]$')">
20
+ <xsl:variable name="s" as="xs:string" select="substring($in, 2, 2)"/>
21
+ <xsl:variable name="d" as="xs:integer" select="p:hex-to-dec(upper-case($s))"/>
22
+ <xsl:choose>
23
+ <xsl:when test="$d = $unreserved">
24
+ <xsl:variable name="c" as="xs:string" select="codepoints-to-string($d)"/>
25
+ <xsl:sequence select="p:pct-decode-unreserved(substring($in, 4), ($seq, $c))"/>
26
+ </xsl:when>
27
+ <xsl:otherwise>
28
+ <xsl:sequence select="p:pct-decode-unreserved(substring($in, 4), ($seq, '%', $s))"/>
29
+ </xsl:otherwise>
30
+ </xsl:choose>
31
+ </xsl:when>
32
+ <xsl:when test="contains(substring($in, 2), '%')">
33
+ <xsl:variable name="s" as="xs:string" select="substring-before(substring($in, 2), '%')"/>
34
+ <xsl:sequence select="p:pct-decode-unreserved(substring($in, 2 + string-length($s)), ($seq, '%', $s))"/>
35
+ </xsl:when>
36
+ <xsl:otherwise>
37
+ <xsl:sequence select="string-join(($seq, $in), '')"/>
38
+ </xsl:otherwise>
39
+ </xsl:choose>
40
+ </xsl:when>
41
+ <xsl:when test="contains($in, '%')">
42
+ <xsl:variable name="s" as="xs:string" select="substring-before($in, '%')"/>
43
+ <xsl:sequence select="p:pct-decode-unreserved(substring($in, string-length($s)+1), ($seq, $s))"/>
44
+ </xsl:when>
45
+ <xsl:otherwise>
46
+ <xsl:sequence select="string-join(($seq, $in), '')"/>
47
+ </xsl:otherwise>
48
+ </xsl:choose>
49
+ </xsl:function>
50
+
51
+ <!-- Private function to convert a hexadecimal string into decimal -->
52
+ <xsl:function name="p:hex-to-dec" as="xs:integer">
53
+ <xsl:param name="hex" as="xs:string"/>
54
+
55
+ <xsl:variable name="len" as="xs:integer" select="string-length($hex)"/>
56
+ <xsl:choose>
57
+ <xsl:when test="$len eq 0">
58
+ <xsl:sequence select="0"/>
59
+ </xsl:when>
60
+ <xsl:when test="$len eq 1">
61
+ <xsl:sequence select="
62
+ if ($hex eq '0') then 0
63
+ else if ($hex eq '1') then 1
64
+ else if ($hex eq '2') then 2
65
+ else if ($hex eq '3') then 3
66
+ else if ($hex eq '4') then 4
67
+ else if ($hex eq '5') then 5
68
+ else if ($hex eq '6') then 6
69
+ else if ($hex eq '7') then 7
70
+ else if ($hex eq '8') then 8
71
+ else if ($hex eq '9') then 9
72
+ else if ($hex = ('A', 'a')) then 10
73
+ else if ($hex = ('B', 'b')) then 11
74
+ else if ($hex = ('C', 'c')) then 12
75
+ else if ($hex = ('D', 'd')) then 13
76
+ else if ($hex = ('E', 'e')) then 14
77
+ else if ($hex = ('F', 'f')) then 15
78
+ else error(xs:QName('p:hex-to-dec'))
79
+ "/>
80
+ </xsl:when>
81
+ <xsl:otherwise>
82
+ <xsl:sequence select="
83
+ (16 * p:hex-to-dec(substring($hex, 1, $len - 1)))
84
+ + p:hex-to-dec(substring($hex, $len))"/>
85
+ </xsl:otherwise>
86
+ </xsl:choose>
87
+ </xsl:function>
@@ -0,0 +1,174 @@
1
+ <!--
2
+
3
+ wrap-text.xsl
4
+
5
+ Author: John Maurer (jmaurer@hawaii.edu)
6
+ Date: June 2007 (when I was at National Snow and Ice Data Center)
7
+
8
+ This Extensible Stylesheet Language for Transformations (XSLT) document takes
9
+ an input string and outputs it with line wrapping. Lines get wrapped at the
10
+ specified $max-line-length of characters. You can import this XSLT in other
11
+ XSLT files to call the "wrap-text" template for accomplishing this. Here is
12
+ an example import statement:
13
+
14
+ <xsl:import href="wrap-text.xsl"/>
15
+
16
+ The "wrap-text" template uses the "fold" and "chop" helper templates to
17
+ accomplish the end result. "wrap-text" first splits the file up into sections
18
+ before and after blank lines (2 consecutive newlines); each of these sections
19
+ gets passed to the "fold" template, which in turn calls the "chop" template
20
+ to chop up the string into $max-line-length character lines. "fold" indents
21
+ each chopped line by the $indent string, which the user can define as the
22
+ number of spaces that they want to precede every line.
23
+
24
+ For more information on XSLT see:
25
+
26
+ http://en.wikipedia.org/wiki/XSLT
27
+ http://www.w3.org/TR/xslt
28
+
29
+ -->
30
+
31
+ <xsl:stylesheet
32
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33
+ version="1.0">
34
+
35
+ <xsl:output method="text"/>
36
+
37
+ <!-- Define a variable for creating a newline/break: -->
38
+
39
+ <xsl:variable name="newline">
40
+ <xsl:text>
41
+ </xsl:text>
42
+ </xsl:variable>
43
+
44
+ <!-- Define a variable for creating a blank line, which
45
+ is two consecutive newlines characters: -->
46
+
47
+ <xsl:variable name="blank-line" select="concat( $newline, $newline )"/>
48
+
49
+ <!-- Define a variable for a single space character: -->
50
+
51
+ <xsl:variable name="space" select="' '"/>
52
+
53
+ <!-- A template to wrap text into lines of $max-line-length.
54
+ Each line will get one indent: -->
55
+
56
+ <xsl:template name="wrap-text">
57
+ <xsl:param name="original-string"/>
58
+ <xsl:param name="max-line-length"/>
59
+ <xsl:param name="indent"/>
60
+ <xsl:choose>
61
+ <xsl:when test="contains( $original-string, $blank-line )">
62
+ <xsl:comment>Call "fold" on the string before the blank line to wrap this text:</xsl:comment>
63
+ <xsl:call-template name="fold">
64
+ <xsl:with-param name="original-string" select="substring-before( $original-string, $blank-line )"/>
65
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
66
+ <xsl:with-param name="indent" select="$indent"/>
67
+ </xsl:call-template>
68
+ <xsl:value-of select="$newline"/>
69
+ <xsl:comment>Call wrap-text recursively on remaining text after the blank line:</xsl:comment>
70
+ <xsl:call-template name="wrap-text">
71
+ <xsl:with-param name="original-string" select="substring-after( $original-string, $blank-line )"/>
72
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
73
+ <xsl:with-param name="indent" select="$indent"/>
74
+ </xsl:call-template>
75
+ </xsl:when>
76
+ <xsl:otherwise>
77
+ <xsl:comment>If the text does not contain any blank lines, call "fold" to wrap the text:</xsl:comment>
78
+ <xsl:call-template name="fold">
79
+ <xsl:with-param name="original-string" select="$original-string"/>
80
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
81
+ <xsl:with-param name="indent" select="$indent"/>
82
+ </xsl:call-template>
83
+ </xsl:otherwise>
84
+ </xsl:choose>
85
+ </xsl:template>
86
+
87
+ <xsl:template name="fold">
88
+ <xsl:param name="original-string"/>
89
+ <xsl:param name="max-line-length"/>
90
+ <xsl:param name="indent"/>
91
+ <xsl:variable name="print-string">
92
+ <xsl:choose>
93
+ <xsl:when test="string-length( $original-string ) &gt; number( $max-line-length )">
94
+ <xsl:comment>Text is longer than max, chop it down and print next line:</xsl:comment>
95
+ <xsl:call-template name="chop">
96
+ <xsl:with-param name="newstring" select="''"/>
97
+ <xsl:with-param name="original-string" select="$original-string"/>
98
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
99
+ </xsl:call-template>
100
+ </xsl:when>
101
+ <xsl:otherwise>
102
+ <xsl:comment>Text is less than max length, so print the whole thing:</xsl:comment>
103
+ <xsl:value-of select="$original-string"/>
104
+ </xsl:otherwise>
105
+ </xsl:choose>
106
+ </xsl:variable>
107
+ <xsl:value-of select="$indent"/>
108
+ <xsl:value-of select="$print-string"/>
109
+ <xsl:value-of select="$newline"/>
110
+ <xsl:comment>Check if there is any remaining text after the above chop:</xsl:comment>
111
+ <xsl:variable name="remaining-string" select="substring-after( $original-string, $print-string )"/>
112
+ <xsl:if test="string-length( $remaining-string )">
113
+ <xsl:comment>Call "fold" recursively on the remaining text:</xsl:comment>
114
+ <xsl:call-template name="fold">
115
+ <xsl:with-param name="original-string" select="$remaining-string"/>
116
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
117
+ <xsl:with-param name="indent" select="$indent"/>
118
+ </xsl:call-template>
119
+ </xsl:if>
120
+ </xsl:template>
121
+
122
+ <xsl:template name="chop">
123
+ <xsl:param name="newstring"/>
124
+ <xsl:param name="original-string"/>
125
+ <xsl:param name="max-line-length"/>
126
+ <xsl:variable name="substring-before-space">
127
+ <xsl:comment>This is the part of the string before the first occuring space character, if any:</xsl:comment>
128
+ <xsl:choose>
129
+ <xsl:when test="contains( $original-string, $space )">
130
+ <xsl:comment>This text contains a space character; chop it off at the first space and add to newstring:</xsl:comment>
131
+ <xsl:value-of select="concat( $newstring, substring-before( $original-string, $space ), $space )"/>
132
+ </xsl:when>
133
+ <xsl:otherwise>
134
+ <xsl:comment>This text does not contain any space characters so use it all:</xsl:comment>
135
+ <xsl:value-of select="concat( $newstring, $original-string )"/>
136
+ </xsl:otherwise>
137
+ </xsl:choose>
138
+ </xsl:variable>
139
+ <xsl:variable name="substring-after-space">
140
+ <xsl:comment>This is the part of the string after the first occuring space character, if any:</xsl:comment>
141
+ <xsl:choose>
142
+ <xsl:when test="contains( $original-string, $space )">
143
+ <xsl:comment>This text contains a space character; take what is after the first space:</xsl:comment>
144
+ <xsl:value-of select="substring-after( $original-string, $space )"/>
145
+ </xsl:when>
146
+ <xsl:otherwise>
147
+ <xsl:comment>This text does not contain any space characters so define a null string here:</xsl:comment>
148
+ <xsl:value-of select="''"/>
149
+ </xsl:otherwise>
150
+ </xsl:choose>
151
+ </xsl:variable>
152
+ <xsl:choose>
153
+ <xsl:when test="( string-length( $substring-before-space ) &lt; number( $max-line-length ) ) and $substring-after-space">
154
+ <xsl:comment>Call "chop" recursively to build up the string until it is just greater than the max length:</xsl:comment>
155
+ <xsl:variable name="return-value">
156
+ <xsl:call-template name="chop">
157
+ <xsl:with-param name="newstring" select="$substring-before-space"/>
158
+ <xsl:with-param name="original-string" select="$substring-after-space"/>
159
+ <xsl:with-param name="max-line-length" select="$max-line-length"/>
160
+ </xsl:call-template>
161
+ </xsl:variable>
162
+ <xsl:value-of select="$return-value"/>
163
+ </xsl:when>
164
+ <xsl:when test="$newstring">
165
+ <xsl:value-of select="$newstring"/>
166
+ </xsl:when>
167
+ <xsl:otherwise>
168
+ <xsl:comment>Return the whole string if it is already less than the max length:</xsl:comment>
169
+ <xsl:value-of select="$substring-before-space"/>
170
+ </xsl:otherwise>
171
+ </xsl:choose>
172
+ </xsl:template>
173
+
174
+ </xsl:stylesheet>
@@ -8,9 +8,14 @@ RSpec.describe GeoCombine::Fgdc do
8
8
  expect(fgdc_object).to be_an GeoCombine::Fgdc
9
9
  end
10
10
  end
11
- describe '#xsl' do
11
+ describe '#xsl_geoblacklight' do
12
12
  it 'should be defined' do
13
- expect(fgdc_object.xsl).to be_an Nokogiri::XSLT::Stylesheet
13
+ expect(fgdc_object.xsl_geoblacklight).to be_an Nokogiri::XSLT::Stylesheet
14
+ end
15
+ end
16
+ describe '#xsl_html'do
17
+ it 'should be defined' do
18
+ expect(fgdc_object.xsl_html).to be_an Nokogiri::XSLT::Stylesheet
14
19
  end
15
20
  end
16
21
  describe '#to_geoblacklight' do
@@ -19,4 +24,9 @@ RSpec.describe GeoCombine::Fgdc do
19
24
  expect(fgdc_object.to_geoblacklight).to be_an GeoCombine::Geoblacklight
20
25
  end
21
26
  end
27
+ describe '#to_html' do
28
+ it 'should create a transformation of the metadata as a String' do
29
+ expect(fgdc_object.to_html).to be_an String
30
+ end
31
+ end
22
32
  end
@@ -8,9 +8,14 @@ RSpec.describe GeoCombine::Iso19139 do
8
8
  expect(iso_object).to be_an GeoCombine::Iso19139
9
9
  end
10
10
  end
11
- describe '#xsl' do
11
+ describe '#xsl_geoblacklight' do
12
12
  it 'should be defined' do
13
- expect(iso_object.xsl).to be_an Nokogiri::XSLT::Stylesheet
13
+ expect(iso_object.xsl_geoblacklight).to be_an Nokogiri::XSLT::Stylesheet
14
+ end
15
+ end
16
+ describe '#xsl_html' do
17
+ it 'should be defined' do
18
+ expect(iso_object.xsl_geoblacklight).to be_an Nokogiri::XSLT::Stylesheet
14
19
  end
15
20
  end
16
21
  describe '#to_geoblacklight' do
@@ -18,4 +23,9 @@ RSpec.describe GeoCombine::Iso19139 do
18
23
  expect(iso_object.to_geoblacklight).to be_an GeoCombine::Geoblacklight
19
24
  end
20
25
  end
26
+ describe '#to_html' do
27
+ it 'should create a transformation of the metadata as a String' do
28
+ expect(iso_object.to_html).to be_an String
29
+ end
30
+ end
21
31
  end
@@ -18,5 +18,6 @@ RSpec.describe GeoCombine::Metadata do
18
18
  expect(metadata_object.metadata.css('Author').count).to eq 2
19
19
  end
20
20
  end
21
- # GeoCombine subclasses should individually test `to_geoblacklight` method
21
+ # GeoCombine subclasses should individually test `to_geoblacklight` and
22
+ # `to_html` methods
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_combine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsolr
@@ -102,7 +102,22 @@ files:
102
102
  - lib/geo_combine/version.rb
103
103
  - lib/tasks/geo_combine.rake
104
104
  - lib/xslt/fgdc2geoBL.xsl
105
+ - lib/xslt/fgdc2html.xsl
105
106
  - lib/xslt/iso2geoBL.xsl
107
+ - lib/xslt/iso2html.xsl
108
+ - lib/xslt/utils/convert-enumerations.xsl
109
+ - lib/xslt/utils/convert-latlong.xsl
110
+ - lib/xslt/utils/decode-uri/base.css
111
+ - lib/xslt/utils/decode-uri/index.html
112
+ - lib/xslt/utils/elements-fgdc.xml
113
+ - lib/xslt/utils/elements-iso.xml
114
+ - lib/xslt/utils/printFormatted.xsl
115
+ - lib/xslt/utils/printTextLines.xsl
116
+ - lib/xslt/utils/replace-newlines.xsl
117
+ - lib/xslt/utils/replace-string.xsl
118
+ - lib/xslt/utils/strip-digits.xsl
119
+ - lib/xslt/utils/url-decode.xsl
120
+ - lib/xslt/utils/wrap-text.xsl
106
121
  - spec/fixtures/xml_docs.rb
107
122
  - spec/helpers.rb
108
123
  - spec/lib/geo_combine/fgdc_spec.rb