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.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/geo_combine/fgdc.rb +9 -2
- data/lib/geo_combine/iso19139.rb +9 -2
- data/lib/geo_combine/version.rb +1 -1
- data/lib/geo_combine.rb +10 -2
- data/lib/xslt/fgdc2html.xsl +1034 -0
- data/lib/xslt/iso2html.xsl +1745 -0
- data/lib/xslt/utils/convert-enumerations.xsl +97 -0
- data/lib/xslt/utils/convert-latlong.xsl +73 -0
- data/lib/xslt/utils/decode-uri/base.css +408 -0
- data/lib/xslt/utils/decode-uri/index.html +29 -0
- data/lib/xslt/utils/elements-fgdc.xml +824 -0
- data/lib/xslt/utils/elements-iso.xml +636 -0
- data/lib/xslt/utils/printFormatted.xsl +267 -0
- data/lib/xslt/utils/printTextLines.xsl +192 -0
- data/lib/xslt/utils/replace-newlines.xsl +97 -0
- data/lib/xslt/utils/replace-string.xsl +80 -0
- data/lib/xslt/utils/strip-digits.xsl +60 -0
- data/lib/xslt/utils/url-decode.xsl +87 -0
- data/lib/xslt/utils/wrap-text.xsl +174 -0
- data/spec/lib/geo_combine/fgdc_spec.rb +12 -2
- data/spec/lib/geo_combine/iso19139_spec.rb +12 -2
- data/spec/lib/geo_combine_spec.rb +2 -1
- metadata +17 -2
@@ -0,0 +1,267 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
|
5
|
+
<!--
|
6
|
+
Print the text of an XML element as preformatted text or wrapped paragraphs,
|
7
|
+
as appropriate. Makes the text readable on screen, and preserves the author's
|
8
|
+
intended formatting.
|
9
|
+
|
10
|
+
Created 6/20/06 Richard.Fozzard@noaa.gov
|
11
|
+
|
12
|
+
@version $Id$
|
13
|
+
|
14
|
+
The stylesheet that imports this file needs to define two callback templates:
|
15
|
+
printFormattedLine Output a line, preserving all formatting (whitespace)
|
16
|
+
printParagraphLine Output a line as a continuous paragraph (word-wrapped)
|
17
|
+
both with the param "line", the one line string to print.
|
18
|
+
|
19
|
+
Each callback template then outputs the "line" string as desired (e.g. HTML,
|
20
|
+
text, XML). These templates can have some optional params which printFormatted
|
21
|
+
will pass through as needed:
|
22
|
+
"restOfString" Useful for doing something different at the end, e.g. no <P>
|
23
|
+
"optional-param-1" Useful for passing indent values
|
24
|
+
"optional-param-2" or word wrap widths...
|
25
|
+
"optional-param-3" or whatever...
|
26
|
+
|
27
|
+
Then, whenever a string of one or more lines needs to be output, call the
|
28
|
+
printFormatted template with the params:
|
29
|
+
"elementContent" a one or more line string to print
|
30
|
+
"formattedSectionElement" Name of element to wrap a sequence of formatted lines
|
31
|
+
defaults to 'PRE', can be none, i.e. ''
|
32
|
+
plus any of the desired optional params for the callbacks
|
33
|
+
-->
|
34
|
+
|
35
|
+
|
36
|
+
<!--
|
37
|
+
g-fold-width
|
38
|
+
This parameter specifies the maximum length of a line when the
|
39
|
+
formattedSectionElement (<pre> by default) is used. The browser
|
40
|
+
may wrap PRE text at this width.
|
41
|
+
[only works in Firefox 1+]
|
42
|
+
-->
|
43
|
+
<!-- xsl:param name="g-fold-width" select="'80'"/ -->
|
44
|
+
|
45
|
+
|
46
|
+
<!-- Whitespace characters -->
|
47
|
+
<xsl:variable name="newline">
|
48
|
+
<xsl:text> </xsl:text>
|
49
|
+
</xsl:variable>
|
50
|
+
|
51
|
+
<xsl:variable name="tab">
|
52
|
+
<xsl:text>	</xsl:text>
|
53
|
+
</xsl:variable>
|
54
|
+
|
55
|
+
|
56
|
+
<xsl:template name="printFormatted">
|
57
|
+
<!-- string to print out -->
|
58
|
+
<xsl:param name="elementContent"/>
|
59
|
+
<!-- Name of element to wrap a sequence of formatted lines.
|
60
|
+
Set to empty string for no element, i.e. plain text output. -->
|
61
|
+
<xsl:param name="formattedSectionElement" select="'PRE'"/>
|
62
|
+
<!-- used internally to skip 1 or more formatted lines -->
|
63
|
+
<xsl:param name="skipFormattedLines" select="false()"/>
|
64
|
+
<!-- if needed by callback template: -->
|
65
|
+
<xsl:param name="optional-param-1"/>
|
66
|
+
<xsl:param name="optional-param-2"/>
|
67
|
+
<xsl:param name="optional-param-3"/>
|
68
|
+
|
69
|
+
<xsl:if test="$elementContent"><!-- if not at end of string -->
|
70
|
+
<xsl:variable name="containsNewline" select="contains($elementContent,$newline)"/>
|
71
|
+
<xsl:variable name="firstLine">
|
72
|
+
<xsl:call-template name="strip-trailing-whitespace">
|
73
|
+
<xsl:with-param name="content">
|
74
|
+
<xsl:choose>
|
75
|
+
<xsl:when test="$containsNewline">
|
76
|
+
<xsl:value-of select="substring-before($elementContent,$newline)"/>
|
77
|
+
</xsl:when>
|
78
|
+
<xsl:otherwise>
|
79
|
+
<xsl:value-of select="$elementContent"/>
|
80
|
+
</xsl:otherwise>
|
81
|
+
</xsl:choose>
|
82
|
+
</xsl:with-param>
|
83
|
+
</xsl:call-template>
|
84
|
+
</xsl:variable>
|
85
|
+
|
86
|
+
<xsl:variable name="restOfString" select="substring-after($elementContent,$newline)"/>
|
87
|
+
|
88
|
+
<!-- This line is formatted if it has 3 spaces or a tab or empty line -->
|
89
|
+
<xsl:variable name="thisLineFormatted"
|
90
|
+
select="$firstLine = '' or contains($firstLine,' ') or contains($firstLine,$tab)"/>
|
91
|
+
|
92
|
+
|
93
|
+
<xsl:choose>
|
94
|
+
<!-- if a formatted line -->
|
95
|
+
<xsl:when test="$thisLineFormatted = true()">
|
96
|
+
|
97
|
+
<!-- if at start of a formatted section, and it's a non-empty line before the end of the element, print it -->
|
98
|
+
<xsl:if test="not($skipFormattedLines) and (normalize-space($firstLine) or normalize-space($restOfString))">
|
99
|
+
<xsl:choose>
|
100
|
+
<!-- if specified, wrap a formatted section (1 or more lines) in an element -->
|
101
|
+
<xsl:when test="$formattedSectionElement">
|
102
|
+
<xsl:element name="{$formattedSectionElement}">
|
103
|
+
<xsl:attribute name="wrap"/><!-- works on Firefox 1.5+, not on IE 6/7, Safari 2 -->
|
104
|
+
<!-- xsl:attribute name="width"><xsl:value-of select="$g-fold-width"/></xsl:attribute -->
|
105
|
+
<xsl:call-template name="printFormattedSection">
|
106
|
+
<xsl:with-param name="elementContent" select="$elementContent"/>
|
107
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
108
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
109
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
110
|
+
</xsl:call-template>
|
111
|
+
</xsl:element>
|
112
|
+
</xsl:when>
|
113
|
+
|
114
|
+
<!-- else if no element specified,
|
115
|
+
output a formatted section (1 or more lines) directly -->
|
116
|
+
<xsl:otherwise>
|
117
|
+
<xsl:call-template name="printFormattedSection">
|
118
|
+
<xsl:with-param name="elementContent" select="$elementContent"/>
|
119
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
120
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
121
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
122
|
+
</xsl:call-template>
|
123
|
+
</xsl:otherwise>
|
124
|
+
</xsl:choose>
|
125
|
+
</xsl:if>
|
126
|
+
|
127
|
+
<!-- go to next line, recursively until next non-formatted line or end of string -->
|
128
|
+
<xsl:call-template name="printFormatted">
|
129
|
+
<xsl:with-param name="elementContent" select="$restOfString"/>
|
130
|
+
<xsl:with-param name="formattedSectionElement" select="$formattedSectionElement"/>
|
131
|
+
<xsl:with-param name="skipFormattedLines" select="true()"/>
|
132
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
133
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
134
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
135
|
+
</xsl:call-template>
|
136
|
+
|
137
|
+
</xsl:when>
|
138
|
+
|
139
|
+
<!-- else not a formatted line; treat as paragraph -->
|
140
|
+
<xsl:otherwise>
|
141
|
+
|
142
|
+
<!-- make callback to importing stylesheet to print the paragraph -->
|
143
|
+
<xsl:call-template name="printParagraphLine">
|
144
|
+
<xsl:with-param name="line" select="$firstLine"/>
|
145
|
+
<xsl:with-param name="restOfString" select="$restOfString"/>
|
146
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
147
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
148
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
149
|
+
</xsl:call-template>
|
150
|
+
|
151
|
+
<!-- go to next line, recursively until non-formatted line or end of string -->
|
152
|
+
<xsl:call-template name="printFormatted">
|
153
|
+
<xsl:with-param name="elementContent" select="$restOfString"/>
|
154
|
+
<xsl:with-param name="formattedSectionElement" select="$formattedSectionElement"/>
|
155
|
+
<xsl:with-param name="skipFormattedLines" select="false()"/>
|
156
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
157
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
158
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
159
|
+
</xsl:call-template>
|
160
|
+
|
161
|
+
</xsl:otherwise>
|
162
|
+
</xsl:choose>
|
163
|
+
|
164
|
+
</xsl:if>
|
165
|
+
</xsl:template>
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<xsl:template name="printFormattedSection">
|
170
|
+
<xsl:param name="elementContent"/><!-- string to print out -->
|
171
|
+
<!-- if needed by callback template: -->
|
172
|
+
<xsl:param name="optional-param-1"/>
|
173
|
+
<xsl:param name="optional-param-2"/>
|
174
|
+
<xsl:param name="optional-param-3"/>
|
175
|
+
|
176
|
+
<xsl:if test="$elementContent"><!-- if not at end of string -->
|
177
|
+
<xsl:variable name="firstLine">
|
178
|
+
<xsl:call-template name="strip-trailing-whitespace">
|
179
|
+
<xsl:with-param name="content" select="substring-before($elementContent,$newline)"/>
|
180
|
+
</xsl:call-template>
|
181
|
+
</xsl:variable>
|
182
|
+
|
183
|
+
<xsl:variable name="restOfString" select="substring-after($elementContent,$newline)"/>
|
184
|
+
|
185
|
+
<!-- This line is formatted if it has 3 spaces or a tab or empty line -->
|
186
|
+
<xsl:variable name="thisLineFormatted"
|
187
|
+
select="$firstLine = '' or contains($firstLine,' ') or contains($firstLine,$tab)"/>
|
188
|
+
|
189
|
+
|
190
|
+
<xsl:if test="$thisLineFormatted = true()"><!-- if a formatted line -->
|
191
|
+
<!-- make callback to importing stylesheet to print the formatted line -->
|
192
|
+
<xsl:call-template name="printFormattedLine">
|
193
|
+
<xsl:with-param name="line" select="$firstLine"/>
|
194
|
+
<xsl:with-param name="restOfString" select="$restOfString"/>
|
195
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
196
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
197
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
198
|
+
</xsl:call-template>
|
199
|
+
|
200
|
+
<!-- recursively call self until all formatted lines written -->
|
201
|
+
<xsl:call-template name="printFormattedSection">
|
202
|
+
<xsl:with-param name="elementContent" select="$restOfString"/>
|
203
|
+
<xsl:with-param name="optional-param-1" select="$optional-param-1"/>
|
204
|
+
<xsl:with-param name="optional-param-2" select="$optional-param-2"/>
|
205
|
+
<xsl:with-param name="optional-param-3" select="$optional-param-3"/>
|
206
|
+
</xsl:call-template>
|
207
|
+
</xsl:if>
|
208
|
+
<!-- do nothing and end recursion if we find a non-formatted, plain line -->
|
209
|
+
</xsl:if>
|
210
|
+
|
211
|
+
</xsl:template>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
<!--
|
218
|
+
Strip the leading white space (including newlines or other characters
|
219
|
+
that get translated to white space by normalize-space) from a block
|
220
|
+
of text.
|
221
|
+
|
222
|
+
[Stolen from somewhere on the web using Google.]
|
223
|
+
-->
|
224
|
+
|
225
|
+
<xsl:template name="strip-leading-whitespace">
|
226
|
+
<xsl:param name="content"/>
|
227
|
+
<xsl:variable name="normalized-text" select="normalize-space($content)"/>
|
228
|
+
<xsl:variable name="first-char" select="substring($normalized-text,1,1)"/>
|
229
|
+
<xsl:variable name="leading-spaces" select="substring-before($content,$first-char)"/>
|
230
|
+
<xsl:choose>
|
231
|
+
<xsl:when test="string-length($leading-spaces) > 0">
|
232
|
+
<xsl:value-of select="substring-after($content,$leading-spaces)"/>
|
233
|
+
</xsl:when>
|
234
|
+
<xsl:otherwise>
|
235
|
+
<xsl:value-of select="$content"/>
|
236
|
+
</xsl:otherwise>
|
237
|
+
</xsl:choose>
|
238
|
+
</xsl:template>
|
239
|
+
|
240
|
+
|
241
|
+
<!--
|
242
|
+
Strip the trailing white space (including newlines or other characters
|
243
|
+
that get translated to white space by normalize-space) from a block
|
244
|
+
of text.
|
245
|
+
|
246
|
+
[Stolen from somewhere on the web using Google.]
|
247
|
+
-->
|
248
|
+
|
249
|
+
<xsl:template name="strip-trailing-whitespace">
|
250
|
+
<xsl:param name="content"/>
|
251
|
+
<xsl:param name="i" select="string-length($content)"/>
|
252
|
+
<xsl:choose>
|
253
|
+
<xsl:when test="translate(substring($content, $i, 1), ' 	 ', '')">
|
254
|
+
<xsl:value-of select="substring($content,1,$i)"/>
|
255
|
+
</xsl:when>
|
256
|
+
<xsl:when test="$i < 2"/><!-- done! -->
|
257
|
+
<xsl:otherwise>
|
258
|
+
<xsl:call-template name="strip-trailing-whitespace">
|
259
|
+
<xsl:with-param name="content" select="$content"/>
|
260
|
+
<xsl:with-param name="i" select="$i - 1"/>
|
261
|
+
</xsl:call-template>
|
262
|
+
</xsl:otherwise>
|
263
|
+
</xsl:choose>
|
264
|
+
|
265
|
+
</xsl:template>
|
266
|
+
|
267
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,192 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
|
5
|
+
<!--
|
6
|
+
Print an XML element as plain formatted text or wrapped paragraphs,
|
7
|
+
as appropriate. Makes the text readable on screen, and preserves the author's
|
8
|
+
intended formatting.
|
9
|
+
|
10
|
+
[The 'fold' and 'chop' templates come from original xml-to-text.xsl by Joe
|
11
|
+
Shirley.]
|
12
|
+
|
13
|
+
Created 6/20/06 Richard.Fozzard@noaa.gov
|
14
|
+
|
15
|
+
@version $Id$
|
16
|
+
|
17
|
+
This file defines two callback templates used by printFormatted.xsl:
|
18
|
+
printFormattedLine Output a line, preserving all formatting (whitespace)
|
19
|
+
printParagraphLine Output a line as a continuous paragraph (word-wrapped)
|
20
|
+
|
21
|
+
-->
|
22
|
+
|
23
|
+
<!--
|
24
|
+
g-fold-width
|
25
|
+
This parameter specifies the maximum length of a line when the
|
26
|
+
'fold' text formatting option is chosen. This parameter is ignored
|
27
|
+
for other text formatting options.
|
28
|
+
-->
|
29
|
+
<xsl:param name="g-fold-width" select="'80'"/>
|
30
|
+
|
31
|
+
<!--
|
32
|
+
g-fold-character
|
33
|
+
This parameter specifies where a line may be broken when the
|
34
|
+
'fold' text formatting option is chosen. This parameter is ignored
|
35
|
+
for other text formatting options.
|
36
|
+
-->
|
37
|
+
<xsl:param name="g-fold-character" select="' '"/>
|
38
|
+
|
39
|
+
<xsl:variable name="newline">
|
40
|
+
<xsl:text> </xsl:text>
|
41
|
+
</xsl:variable>
|
42
|
+
|
43
|
+
<xsl:variable name="tab">
|
44
|
+
<xsl:text>	</xsl:text>
|
45
|
+
</xsl:variable>
|
46
|
+
|
47
|
+
<!-- Output a single line formatted with all white space preserved. Indent each line
|
48
|
+
to the current indent level.
|
49
|
+
-->
|
50
|
+
<xsl:template name="printFormattedLine">
|
51
|
+
<xsl:param name="line"/>
|
52
|
+
<xsl:param name="restOfString"/>
|
53
|
+
<xsl:param name="optional-param-1"/>
|
54
|
+
|
55
|
+
<xsl:variable name="indent" select="$optional-param-1"/>
|
56
|
+
|
57
|
+
<!-- Print next line, unless it's a blank line after final text line. -->
|
58
|
+
<xsl:if test="(string-length($line) > 0) or (string-length(normalize-space($restOfString)) > 0)">
|
59
|
+
<xsl:value-of select="$indent"/>
|
60
|
+
<xsl:value-of select="$line"/>
|
61
|
+
<xsl:value-of select="$newline"/>
|
62
|
+
</xsl:if>
|
63
|
+
|
64
|
+
</xsl:template>
|
65
|
+
|
66
|
+
|
67
|
+
<!-- Output a single line formatted as a word-wrapped paragraph. Indent each line
|
68
|
+
to the current indent level. Use 'fold' template to do the word-wrapping.
|
69
|
+
-->
|
70
|
+
<xsl:template name="printParagraphLine">
|
71
|
+
<xsl:param name="line"/>
|
72
|
+
<xsl:param name="restOfString"/>
|
73
|
+
<xsl:param name="optional-param-1"/>
|
74
|
+
<xsl:param name="optional-param-2"/>
|
75
|
+
|
76
|
+
<xsl:variable name="indent" select="$optional-param-1"/>
|
77
|
+
<xsl:variable name="length" select="$optional-param-2"/>
|
78
|
+
|
79
|
+
<!-- Print line with 'fold', unless it's a blank line after final text line. -->
|
80
|
+
<xsl:if test="(string-length($line) > 0) or (string-length(normalize-space($restOfString)) > 0)">
|
81
|
+
<xsl:value-of select="$indent"/><!-- fold doesn't indent first line -->
|
82
|
+
<xsl:call-template name="fold">
|
83
|
+
<xsl:with-param name="original-string" select="normalize-space($line)"/>
|
84
|
+
<xsl:with-param name="length" select="$length"/>
|
85
|
+
<xsl:with-param name="indent" select="$indent"/>
|
86
|
+
</xsl:call-template>
|
87
|
+
</xsl:if>
|
88
|
+
|
89
|
+
</xsl:template>
|
90
|
+
|
91
|
+
<!--
|
92
|
+
Text formatting template. Create line breaks. Indent each line to
|
93
|
+
the current indent level. Return the next line each time the
|
94
|
+
template is called.
|
95
|
+
-->
|
96
|
+
|
97
|
+
<xsl:template name="fold">
|
98
|
+
<xsl:param name="original-string"/>
|
99
|
+
<xsl:param name="length"/>
|
100
|
+
<xsl:param name="indent"/>
|
101
|
+
<xsl:param name="fold-width" select="$g-fold-width"/>
|
102
|
+
<xsl:variable name="printstring">
|
103
|
+
<xsl:choose>
|
104
|
+
<xsl:when test="string-length($original-string) > number($length)">
|
105
|
+
<!-- Text is longer than max, chop it down and print next line. -->
|
106
|
+
<xsl:call-template name="chop">
|
107
|
+
<xsl:with-param name="newstring" select="''"/>
|
108
|
+
<xsl:with-param name="original-string" select="$original-string"/>
|
109
|
+
<xsl:with-param name="length" select="$length"/>
|
110
|
+
</xsl:call-template>
|
111
|
+
</xsl:when>
|
112
|
+
<xsl:otherwise>
|
113
|
+
<xsl:value-of select="$original-string"/>
|
114
|
+
</xsl:otherwise>
|
115
|
+
</xsl:choose>
|
116
|
+
</xsl:variable>
|
117
|
+
<xsl:value-of select="$printstring"/>
|
118
|
+
<xsl:value-of select="$newline"/>
|
119
|
+
<xsl:variable name="str" select="substring-after($original-string, $printstring)"/>
|
120
|
+
<xsl:if test="string-length($str)">
|
121
|
+
<!-- More text, call fold recursively. -->
|
122
|
+
<xsl:value-of select="$indent"/>
|
123
|
+
<xsl:call-template name="fold">
|
124
|
+
<xsl:with-param name="original-string" select="$str"/>
|
125
|
+
<xsl:with-param name="length" select="number($fold-width) - string-length($indent)"/>
|
126
|
+
<xsl:with-param name="indent" select="$indent"/>
|
127
|
+
</xsl:call-template>
|
128
|
+
</xsl:if>
|
129
|
+
</xsl:template>
|
130
|
+
|
131
|
+
|
132
|
+
<!--
|
133
|
+
Create line breaks. Break only at specified line break
|
134
|
+
character. If possible keep lines less than a specified maximum
|
135
|
+
length, otherwise break at first acceptable character after
|
136
|
+
maximum length. Return one line each time the template is called.
|
137
|
+
-->
|
138
|
+
|
139
|
+
<xsl:template name="chop">
|
140
|
+
<xsl:param name="newstring"/>
|
141
|
+
<xsl:param name="original-string"/>
|
142
|
+
<xsl:param name="char" select="$g-fold-character"/>
|
143
|
+
<xsl:param name="length"/>
|
144
|
+
<xsl:variable name="str1">
|
145
|
+
<!-- str1 is the part before the break. -->
|
146
|
+
<xsl:choose>
|
147
|
+
<xsl:when test="contains($original-string, $char)">
|
148
|
+
<!-- The text contains a break character, chop it off. -->
|
149
|
+
<xsl:value-of select="concat($newstring, substring-before($original-string, $char), $char)"/>
|
150
|
+
</xsl:when>
|
151
|
+
<xsl:otherwise>
|
152
|
+
<!-- The text contains no break character, use it all. -->
|
153
|
+
<xsl:value-of select="concat($newstring, $original-string)"/>
|
154
|
+
</xsl:otherwise>
|
155
|
+
</xsl:choose>
|
156
|
+
</xsl:variable>
|
157
|
+
<xsl:variable name="str2">
|
158
|
+
<!-- str2 is the part after the break. -->
|
159
|
+
<xsl:choose>
|
160
|
+
<xsl:when test="contains($original-string, $char)">
|
161
|
+
<!-- The text contains a break character, take what is after that. -->
|
162
|
+
<xsl:value-of select="substring-after($original-string, $char)"/>
|
163
|
+
</xsl:when>
|
164
|
+
<xsl:otherwise>
|
165
|
+
<!-- The text contains no break character, use an empty string. -->
|
166
|
+
<xsl:value-of select="''"/>
|
167
|
+
</xsl:otherwise>
|
168
|
+
</xsl:choose>
|
169
|
+
</xsl:variable>
|
170
|
+
<xsl:choose>
|
171
|
+
<xsl:when test="(string-length($str1) < number($length)) and $str2">
|
172
|
+
<xsl:variable name="return-value">
|
173
|
+
<xsl:call-template name="chop">
|
174
|
+
<xsl:with-param name="newstring" select="$str1"/>
|
175
|
+
<xsl:with-param name="original-string" select="$str2"/>
|
176
|
+
<xsl:with-param name="char" select="$char"/>
|
177
|
+
<xsl:with-param name="length" select="$length"/>
|
178
|
+
</xsl:call-template>
|
179
|
+
</xsl:variable>
|
180
|
+
<xsl:value-of select="$return-value"/>
|
181
|
+
</xsl:when>
|
182
|
+
<xsl:when test="$newstring">
|
183
|
+
<xsl:value-of select="$newstring"/>
|
184
|
+
</xsl:when>
|
185
|
+
<xsl:otherwise>
|
186
|
+
<xsl:value-of select="$str1"/>
|
187
|
+
</xsl:otherwise>
|
188
|
+
</xsl:choose>
|
189
|
+
</xsl:template>
|
190
|
+
|
191
|
+
|
192
|
+
</xsl:stylesheet>
|
@@ -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>
|