geoblacklight-schema 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/LICENSE +14 -0
- data/README.md +44 -0
- data/bin/fgdc2mods.rb +5 -0
- data/bin/mods2geoblacklight.rb +5 -0
- data/bin/xsltproc-saxon +14 -0
- data/conf/protwords.txt +21 -0
- data/conf/schema.xml +158 -0
- data/conf/solrconfig.xml +160 -0
- data/conf/stopwords_en.txt +34 -0
- data/conf/synonyms.txt +29 -0
- data/examples/Gemfile +4 -0
- data/examples/generate-example-doc.rb +42 -0
- data/examples/selected.json +5787 -0
- data/examples/upload-to-solr.rb +50 -0
- data/geoblacklight-schema.gemspec +23 -0
- data/lib/geoblacklight/gazetteer.csv +1011 -0
- data/lib/geoblacklight/gazetteer.rb +104 -0
- data/lib/xslt/arcgis_to_iso19110.xsl +364 -0
- data/lib/xslt/fgdc2mods.xsl +1007 -0
- data/lib/xslt/iso2mods.xsl +939 -0
- data/lib/xslt/mods2geoblacklight.xsl +268 -0
- data/lib/xslt/mods2ogp.xsl +195 -0
- data/tools/fgdc2html/Gemfile +2 -0
- data/tools/fgdc2html/fgdc2html.css +71 -0
- data/tools/fgdc2html/fgdc2html.js +6 -0
- data/tools/fgdc2html/fgdc2html.xsl +1034 -0
- data/tools/fgdc2html/render.rb +30 -0
- data/tools/iso2html/Gemfile +2 -0
- data/tools/iso2html/iso-html.xsl +1745 -0
- data/tools/iso2html/render.rb +24 -0
- data/tools/iso2html/utils/convert-enumerations.xsl +97 -0
- data/tools/iso2html/utils/convert-latlong.xsl +73 -0
- data/tools/iso2html/utils/decode-uri/base.css +408 -0
- data/tools/iso2html/utils/decode-uri/index.html +29 -0
- data/tools/iso2html/utils/elements-fgdc.xml +824 -0
- data/tools/iso2html/utils/elements-iso.xml +636 -0
- data/tools/iso2html/utils/printFormatted.xsl +267 -0
- data/tools/iso2html/utils/printTextLines.xsl +192 -0
- data/tools/iso2html/utils/replace-newlines.xsl +97 -0
- data/tools/iso2html/utils/replace-string.xsl +80 -0
- data/tools/iso2html/utils/strip-digits.xsl +60 -0
- data/tools/iso2html/utils/url-decode.xsl +87 -0
- data/tools/iso2html/utils/wrap-text.xsl +174 -0
- data/tools/ogp/0_download.rb +96 -0
- data/tools/ogp/1_validate.rb +225 -0
- data/tools/ogp/2_transform.rb +438 -0
- data/tools/ogp/3_stanford.rb +35 -0
- data/tools/ogp/4_select.rb +189 -0
- data/tools/ogp/5_ingest.rb +55 -0
- data/tools/ogp/Gemfile +2 -0
- data/tools/solr/Gemfile +3 -0
- data/tools/solr/purge.rb +33 -0
- data/tools/solr/upload.rb +35 -0
- data/vendor/.keep +0 -0
- metadata +131 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
<!--
|
2
|
+
|
3
|
+
replace-newlines.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 all newline characters substituted with
|
10
|
+
HTML <br/> elements. This helps maintain paragraph and text structures when
|
11
|
+
using them to output to an HTML document. You can import this XSLT in other
|
12
|
+
XSLT files to call the "replace-newlines" template for accomplishing this.
|
13
|
+
Here is an example import statement:
|
14
|
+
|
15
|
+
<xsl:import href="replace-newlines.xsl"/>
|
16
|
+
|
17
|
+
For more information on XSLT see:
|
18
|
+
|
19
|
+
http://en.wikipedia.org/wiki/XSLT
|
20
|
+
http://www.w3.org/TR/xslt
|
21
|
+
|
22
|
+
-->
|
23
|
+
|
24
|
+
<xsl:stylesheet
|
25
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
26
|
+
version="1.0">
|
27
|
+
|
28
|
+
<xsl:output method="text"/>
|
29
|
+
|
30
|
+
<!-- Define a variable for creating a newline: -->
|
31
|
+
|
32
|
+
<xsl:variable name="newline">
|
33
|
+
<xsl:text>
|
34
|
+
</xsl:text>
|
35
|
+
</xsl:variable>
|
36
|
+
|
37
|
+
<!-- Define a variable for creating an HTML <br/> element: -->
|
38
|
+
|
39
|
+
<xsl:variable name="break">
|
40
|
+
<xsl:text disable-output-escaping="yes"><br/></xsl:text>
|
41
|
+
</xsl:variable>
|
42
|
+
|
43
|
+
<!-- Template to replace newlines with <br/>'s; note the use
|
44
|
+
of "disable-output-escaping" to presever the <br/> in an
|
45
|
+
output HTML document without it being converted to
|
46
|
+
<br/>, which ends up displaying the characters "<br/>"
|
47
|
+
in the output rather than an actual HTML element: -->
|
48
|
+
|
49
|
+
<xsl:template name="replace-newlines">
|
50
|
+
<xsl:param name="element"/>
|
51
|
+
<xsl:variable name="first">
|
52
|
+
<xsl:choose>
|
53
|
+
<xsl:when test="contains( $element, $newline )">
|
54
|
+
<xsl:value-of select="substring-before( $element, $newline )"/>
|
55
|
+
</xsl:when>
|
56
|
+
<xsl:otherwise>
|
57
|
+
<xsl:value-of select="$element"/>
|
58
|
+
</xsl:otherwise>
|
59
|
+
</xsl:choose>
|
60
|
+
</xsl:variable>
|
61
|
+
<xsl:variable name="middle">
|
62
|
+
<xsl:choose>
|
63
|
+
<xsl:when test="contains( $element, $newline )">
|
64
|
+
<xsl:value-of select="$break"/>
|
65
|
+
</xsl:when>
|
66
|
+
<xsl:otherwise>
|
67
|
+
<xsl:text></xsl:text>
|
68
|
+
</xsl:otherwise>
|
69
|
+
</xsl:choose>
|
70
|
+
</xsl:variable>
|
71
|
+
<xsl:variable name="last">
|
72
|
+
<xsl:choose>
|
73
|
+
<xsl:when test="contains( $element, $newline )">
|
74
|
+
<xsl:choose>
|
75
|
+
<xsl:when test="contains( substring-after( $element, $newline ), $newline )">
|
76
|
+
<xsl:call-template name="replace-newlines">
|
77
|
+
<xsl:with-param name="element">
|
78
|
+
<xsl:value-of select="substring-after( $element, $newline )"/>
|
79
|
+
</xsl:with-param>
|
80
|
+
</xsl:call-template>
|
81
|
+
</xsl:when>
|
82
|
+
<xsl:otherwise>
|
83
|
+
<xsl:value-of select="substring-after( $element, $newline )"/>
|
84
|
+
</xsl:otherwise>
|
85
|
+
</xsl:choose>
|
86
|
+
</xsl:when>
|
87
|
+
<xsl:otherwise>
|
88
|
+
<xsl:text></xsl:text>
|
89
|
+
</xsl:otherwise>
|
90
|
+
</xsl:choose>
|
91
|
+
</xsl:variable>
|
92
|
+
<xsl:value-of select="$first" disable-output-escaping="yes"/>
|
93
|
+
<xsl:value-of select="$middle" disable-output-escaping="yes"/>
|
94
|
+
<xsl:value-of select="$last" disable-output-escaping="yes"/>
|
95
|
+
</xsl:template>
|
96
|
+
|
97
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,80 @@
|
|
1
|
+
<!--
|
2
|
+
|
3
|
+
replace-string.xsl
|
4
|
+
|
5
|
+
Author: John Maurer (jmaurer@hawaii.edu)
|
6
|
+
Date: July 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 all $old-string's substituted with the
|
10
|
+
specified $new-string. You can import this XSLT in other XSLT files to call
|
11
|
+
the "replace-string" template for accomplishing this. Here is an example
|
12
|
+
import statement:
|
13
|
+
|
14
|
+
<xsl:import href="replace-string.xsl"/>
|
15
|
+
|
16
|
+
For more information on XSLT see:
|
17
|
+
|
18
|
+
http://en.wikipedia.org/wiki/XSLT
|
19
|
+
http://www.w3.org/TR/xslt
|
20
|
+
|
21
|
+
-->
|
22
|
+
|
23
|
+
<xsl:stylesheet
|
24
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
25
|
+
version="1.0">
|
26
|
+
|
27
|
+
<xsl:output method="text"/>
|
28
|
+
|
29
|
+
<xsl:template name="replace-string">
|
30
|
+
<xsl:param name="element"/>
|
31
|
+
<xsl:param name="old-string"/>
|
32
|
+
<xsl:param name="new-string"/>
|
33
|
+
<xsl:variable name="first">
|
34
|
+
<xsl:choose>
|
35
|
+
<xsl:when test="contains( $element, $old-string )">
|
36
|
+
<xsl:value-of select="substring-before( $element, $old-string )"/>
|
37
|
+
</xsl:when>
|
38
|
+
<xsl:otherwise>
|
39
|
+
<xsl:value-of select="$element"/>
|
40
|
+
</xsl:otherwise>
|
41
|
+
</xsl:choose>
|
42
|
+
</xsl:variable>
|
43
|
+
<xsl:variable name="middle">
|
44
|
+
<xsl:choose>
|
45
|
+
<xsl:when test="contains( $element, $old-string )">
|
46
|
+
<xsl:value-of select="$new-string"/>
|
47
|
+
</xsl:when>
|
48
|
+
<xsl:otherwise>
|
49
|
+
<xsl:text></xsl:text>
|
50
|
+
</xsl:otherwise>
|
51
|
+
</xsl:choose>
|
52
|
+
</xsl:variable>
|
53
|
+
<xsl:variable name="last">
|
54
|
+
<xsl:choose>
|
55
|
+
<xsl:when test="contains( $element, $old-string )">
|
56
|
+
<xsl:choose>
|
57
|
+
<xsl:when test="contains( substring-after( $element, $old-string ), $old-string )">
|
58
|
+
<xsl:call-template name="replace-string">
|
59
|
+
<xsl:with-param name="element" select="substring-after( $element, $old-string )"/>
|
60
|
+
<xsl:with-param name="old-string" select="$old-string"/>
|
61
|
+
<xsl:with-param name="new-string" select="$new-string"/>
|
62
|
+
</xsl:call-template>
|
63
|
+
</xsl:when>
|
64
|
+
<xsl:otherwise>
|
65
|
+
<xsl:value-of select="substring-after( $element, $old-string )"/>
|
66
|
+
</xsl:otherwise>
|
67
|
+
</xsl:choose>
|
68
|
+
</xsl:when>
|
69
|
+
<xsl:otherwise>
|
70
|
+
<xsl:text></xsl:text>
|
71
|
+
</xsl:otherwise>
|
72
|
+
</xsl:choose>
|
73
|
+
</xsl:variable>
|
74
|
+
<!-- Disable output escaping to allow HTML tags to be interpreted: -->
|
75
|
+
<xsl:value-of select="$first" disable-output-escaping="yes"/>
|
76
|
+
<xsl:value-of select="$middle" disable-output-escaping="yes"/>
|
77
|
+
<xsl:value-of select="$last" disable-output-escaping="yes"/>
|
78
|
+
</xsl:template>
|
79
|
+
|
80
|
+
</xsl:stylesheet>
|
@@ -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 ) > 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 ) < 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>
|