-
Notifications
You must be signed in to change notification settings - Fork 32
/
mxdom2mbgl-html.xsl
executable file
·371 lines (317 loc) · 9.52 KB
/
mxdom2mbgl-html.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?xml version="1.0" encoding="utf-8"?>
<!--
This is an XSL stylesheet which converts mscript XML files into HTML.
Use the XSLT command to perform the conversion.
Copyright 1984-2004 The MathWorks, Inc.
$Revision$ $Date$
-->
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> <!ENTITY reg "®"> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">
<xsl:output method="html" indent="yes"/>
<xsl:strip-space elements="mwsh:code"/>
<xsl:template match="mscript">
<html>
<head>
<xsl:comment>
This HTML is auto-generated from an M-file.
To make changes, update the M-file and republish this document.
</xsl:comment>
<xsl:variable name="title">
<xsl:value-of select="//steptitle[@style='document']"/>
</xsl:variable>
<title>
<xsl:if test = "$title != ''"><xsl:value-of select="$title"/></xsl:if>
<xsl:if test = "$title = ''"><xsl:value-of select="m-file"/></xsl:if>
</title>
<meta name="generator">
<xsl:attribute name="content">MATLAB <xsl:value-of select="version"/></xsl:attribute>
</meta>
<meta name="date">
<xsl:attribute name="content"><xsl:value-of select="date"/></xsl:attribute>
</meta>
<meta name="m-file">
<xsl:attribute name="content"><xsl:value-of select="m-file"/></xsl:attribute>
</meta>
<link rel="stylesheet" type="text/css" href="../site.css" />
<style>
body {
background: white;
color: black;
}
p.footer {
text-align: right;
font-size: xx-small;
font-weight: lighter;
font-style: italic;
color: gray;
}
pre.codeinput {
margin-left: 20px;
margin-top: 10px;
margin-bottom: 10px;
background-color: #bbbbbb;
border: solid 1px;
font-size: 10pt;
width: 620px;
}
p
{
margin: 10px;
}
hr
{
color: #bbbbbb;
height: 4;
}
.main
{
border-left-style: solid;
margin-left: 100px;
width: 650px;
}
.upwhitesq
{
position: relative;
left: -5px;
top: -8px;
background: white;
}
.downwhitesq
{
position: relative;
left: 95px;
bottom: 10px;
background: white;
}
img
{
text-align: center;
}
span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}
pre.showbuttons {
margin-left: 30px;
border: solid black 2px;
padding: 4px;
background: #EBEFF3;
}
pre.codeoutput {
margin-left: 20px;
margin-top: 10px;
margin-bottom: 10px;
font-size: 10pt;
width: 520px;
}
pre.error {
color: red;
}
.intro {
width: 650px;
}
</style>
</head>
<body>
<!-- Determine if the there should be an introduction section. -->
<xsl:variable name="hasIntro" select="count(cell[@style = 'overview'])"/>
<!-- If there is an introduction, display it. -->
<xsl:if test = "$hasIntro">
<h1><xsl:value-of select="cell[1]/steptitle"/></h1>
<introduction><div class="intro">
<xsl:apply-templates select="cell[1]/text"/>
</div></introduction>
</xsl:if>
<xsl:variable name="body-cells" select="cell[not(@style = 'overview')]"/>
<!-- Include contents if there are titles for any subsections. -->
<xsl:if test="count(cell/steptitle[not(@style = 'document')])">
<xsl:call-template name="contents">
<xsl:with-param name="body-cells" select="$body-cells"/>
</xsl:call-template>
</xsl:if>
<div class="main">
<!-- Loop over each cell -->
<xsl:for-each select="$body-cells">
<!-- Title of cell -->
<xsl:if test="steptitle">
<xsl:if test="position()>1">
<hr /><div class="upwhitesq"> </div>
</xsl:if>
<xsl:variable name="headinglevel">
<xsl:choose>
<xsl:when test="steptitle[@style = 'document']">h1</xsl:when>
<xsl:otherwise>h2</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$headinglevel}">
<xsl:value-of select="steptitle"/>
<xsl:if test="not(steptitle[@style = 'document'])">
<a>
<xsl:attribute name="name">
<xsl:value-of select="position()"/>
</xsl:attribute>
</a>
</xsl:if>
</xsl:element>
</xsl:if>
<!-- Contents of each cell -->
<xsl:apply-templates select="text"/>
<xsl:apply-templates select="mcode-xmlized"/>
<xsl:apply-templates select="mcodeoutput"/>
<xsl:apply-templates select="img"/>
</xsl:for-each>
<hr /> <div class="upwhitesq"> </div>
</div>
<div class="downwhitesq"> </div>
<!-- OLD FOOTER CODE <p class="footer">
<xsl:value-of select="copyright"/><br/>
Published with MATLAB® <xsl:value-of select="version"/><br/>
</p> -->
<xsl:apply-templates select="originalCode"/>
</body>
</html>
</xsl:template>
<xsl:template name="contents">
<xsl:param name="body-cells"/>
<h2>Contents</h2>
<div><ul>
<xsl:for-each select="$body-cells">
<xsl:if test="./steptitle">
<li><a><xsl:attribute name="href">#<xsl:value-of select="position()"/></xsl:attribute><xsl:value-of select="steptitle"/></a></li>
</xsl:if>
</xsl:for-each>
</ul></div>
</xsl:template>
<!-- HTML Tags in text sections -->
<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="ul">
<div><ul><xsl:apply-templates/></ul></div>
</xsl:template>
<xsl:template match="li">
<li><xsl:apply-templates/></li>
</xsl:template>
<xsl:template match="pre">
<xsl:choose>
<xsl:when test="@class='error'">
<pre class="error"><xsl:apply-templates/></pre>
</xsl:when>
<xsl:otherwise>
<pre><xsl:apply-templates/></pre>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="b">
<b><xsl:apply-templates/></b>
</xsl:template>
<xsl:template match="tt">
<tt><xsl:apply-templates/></tt>
</xsl:template>
<xsl:template match="a">
<a>
<xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
<xsl:apply-templates/>
</a>
</xsl:template>
<!-- Code input and output -->
<xsl:template match="mcode-xmlized">
<pre class="codeinput"><xsl:apply-templates/><xsl:text><!-- g162495 -->
</xsl:text></pre>
</xsl:template>
<xsl:template match="mcodeoutput">
<pre class="codeoutput"><xsl:apply-templates/></pre>
</xsl:template>
<!-- ALTERNATIVE Code input -->
<xsl:template match="XXXmcode-xmlized">
<a>
<xsl:attribute name="name">c<xsl:value-of select="../mcode-count"/></xsl:attribute>
</a>
<pre class="showbuttons">
<a>
<xsl:attribute name="href">#c<xsl:value-of select="(../mcode-count)+1"/></xsl:attribute>
<img align="right" src="http://www-internal.mathworks.com/images/clf/orange_arrow.gif" border="0"/>
</a>
<a>
<xsl:attribute name="href">matlab:<xsl:value-of select="../mcode-flat"/></xsl:attribute>
<img align="right" style="margin-left:4px;" src="http://www-internal/images/clf/yellow_arrow.gif
" border="0"/>
</a>
<xsl:apply-templates/>
</pre>
</xsl:template>
<!-- Figure and model snapshots -->
<xsl:template match="img">
<img vspace="5" hspace="5">
<xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute><xsl:text> </xsl:text>
</img>
</xsl:template>
<!-- Stash original code in HTML for easy slurping later. -->
<xsl:template match="originalCode">
<xsl:variable name="xcomment">
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString" select="."/>
<xsl:with-param name="target" select="'--'"/>
<xsl:with-param name="replacement" select="'REPLACE_WITH_DASH_DASH'"/>
</xsl:call-template>
</xsl:variable>
<xsl:comment>
##### SOURCE BEGIN #####
<xsl:value-of select="$xcomment"/>
##### SOURCE END #####
</xsl:comment>
</xsl:template>
<!-- Colors for syntax-highlighted input code -->
<xsl:template match="mwsh:code">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="mwsh:keywords">
<span class="keyword"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="mwsh:strings">
<span class="string"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="mwsh:comments">
<span class="comment"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="mwsh:unterminated_strings">
<span class="untermstring"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="mwsh:system_commands">
<span class="syscmd"><xsl:value-of select="."/></span>
</xsl:template>
<!-- Footer information -->
<xsl:template match="copyright">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="revision">
<xsl:value-of select="."/>
</xsl:template>
<!-- Search and replace -->
<!-- From http://www.xml.com/lpt/a/2002/06/05/transforming.html -->
<xsl:template name="globalReplace">
<xsl:param name="outputString"/>
<xsl:param name="target"/>
<xsl:param name="replacement"/>
<xsl:choose>
<xsl:when test="contains($outputString,$target)">
<xsl:value-of select=
"concat(substring-before($outputString,$target),$replacement)"/>
<xsl:call-template name="globalReplace">
<xsl:with-param name="outputString"
select="substring-after($outputString,$target)"/>
<xsl:with-param name="target" select="$target"/>
<xsl:with-param name="replacement"
select="$replacement"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$outputString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>