This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entities.xsl
445 lines (377 loc) · 15.9 KB
/
entities.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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?xml version="1.0"?>
<!--
$Id: entities.xsl,v 1.18 2013/12/08 18:43:25 dcarlis Exp $
Generate entity files for MathML
David Carlisle
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:d="data:,dpc"
version="2.0">
<xsl:param name="plane1hack" select="false()"/>
<!--set to true to guard combining characters with a space-->
<xsl:param name="guard-combining" select="false()"/>
<xsl:param name="olddesc" select="false()"/>
<xsl:param name="mml2" select="doc('mml2.xml')"/>
<xsl:param name="xhtml1" select="doc('xhtml1.xml')"/>
<xsl:param name="mathmaptxt"
select="tokenize(unparsed-text('MathMap-9.txt'),'[\r\n]+')"/>
<xsl:key name="mml2" match="char" use="@name"/>
<xsl:variable name="mathmap">
<m>
<xsl:for-each select="$mathmaptxt">
<xsl:analyze-string select="." regex="^([0-9A-F]+);\s*([0-9A-Za-z]+);">
<xsl:matching-substring>
<c hex="U{if(string-length(regex-group(1))=4) then '0' else ''}{regex-group(1)}" id="{regex-group(2)}"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</m>
</xsl:variable>
<xsl:strip-space elements="group"/>
<xsl:output
method="text"
/>
<xsl:variable name="top"> produced by the XSL script entities.xsl
from input data in unicode.xml.
Copyright 1998 - 2016 W3C.
Use and distribution of this code are permitted under the terms of
either of the following two licences:
1) W3C Software Notice and License.
http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html
2) The license used for the WHATWG HTML specification,
which states, in full:
You are granted a license to use, reproduce and create derivative
works of this document.
Please report any errors to David Carlisle
via the public W3C list www-math@w3.org.
The numeric character values assigned to each entity
(should) match the Unicode assignments in Unicode 6.x.
</xsl:variable>
<xsl:variable name="vs1">
References to the VARIANT SELECTOR 1 character (&#x0FE00;)
should match the uses listed in Unicode Technical Report 25.
</xsl:variable>
<xsl:variable name="copy1">
Entity names in this file are derived from files carrying the
following notice:
</xsl:variable>
<xsl:variable name="copy">
(C) International Organization for Standardization WQYZ
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
</xsl:variable>
<xsl:template match="set">
<xsl:param name="write-file" select="true()"/>
<xsl:variable name="d" select="../@name"/>
<xsl:variable name="f">
<xsl:choose>
<xsl:when test="starts-with(@name,'957')"><xsl:value-of select="substring(@name,11)"/></xsl:when>
<xsl:when test="starts-with(@name,'88')"><xsl:value-of select="substring-after(@name,'-')"/></xsl:when>
<!--
<xsl:when test="starts-with(@name,'html')"><xsl:value-of select="substring-after(@name,'-')"/></xsl:when>
-->
<xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:text> <!ENTITY % </xsl:text>
<xsl:value-of select="$f"/>
<xsl:text> PUBLIC "</xsl:text>
<xsl:value-of select="@fpi"/>
<xsl:text>" "</xsl:text>
<xsl:value-of select="$f"/>
<xsl:text>.ent"> %</xsl:text>
<xsl:value-of select="$f"/>
<xsl:text>;</xsl:text>
<xsl:if test="$write-file">
<xsl:result-document method="text" href="{$d}/{$f}.ent">
<xsl:text>
<!--
File </xsl:text>
<xsl:value-of select="$f"/>
<xsl:text>.ent</xsl:text>
<xsl:copy-of select="$top"/>
<xsl:if test="key('set',@name)/../@id[contains(.,'-0FE00')]">
<xsl:copy-of select="$vs1"/>
</xsl:if>
<xsl:choose>
<xsl:when test="starts-with(@name,'9573') and replace(@name,'2003','1991')=../../group[@name='iso9573-1991']/set/@name">
<xsl:value-of select="$copy1"/>
<xsl:value-of select="translate($copy,'WQYZ','1991')"/>
</xsl:when>
<xsl:when test="starts-with(@name,'9573')">
<xsl:value-of select="$copy1"/>
<xsl:value-of select="translate($copy,'WQYZ','1986')"/>
</xsl:when>
<xsl:when test="starts-with(@name,'9573-2003')">
<xsl:value-of select="translate($copy,'WQYZ','2003')"/>
</xsl:when>
<xsl:when test="starts-with(@name,'9573-2004')">
<xsl:value-of select="translate($copy,'WQYZ','2004')"/>
</xsl:when>
<xsl:when test="starts-with(@name,'8')">
<xsl:value-of select="$copy1"/>
<xsl:value-of select="translate($copy,'WQYZ','1986')"/>
</xsl:when>
</xsl:choose>
<xsl:text>
-->
</xsl:text>
<!--
<xsl:if test="@fpi">Public identifier: <xsl:value-of select="@fpi"/>//XML</xsl:if>
System identifier: http://www.w3.org/2003/entities/<xsl:value-of select="$d"/>/<xsl:value-of select="$f"/>.ent
<xsl:if test="@fpi">The public identifier should always be used verbatim.
</xsl:if>The system identifier may be changed to suit local requirements.
Typical invocation:
<!ENTITY % <xsl:value-of select="$f"/><xsl:if test="@fpi"> PUBLIC
"<xsl:value-of select="@fpi"/>//XML"</xsl:if><xsl:if test="not(@fpi)"> SYSTEM</xsl:if>
"http://www.w3.org/2003/entities/<xsl:value-of select="$d"/>/<xsl:value-of select="$f"/>.ent"
>
%<xsl:value-of select="$f"/>;
<xsl:text>-->
</xsl:text>
<xsl:if test="$plane1hack and key('set',@name)/../@id[starts-with(.,'U1D')]">
<xsl:text><!ENTITY % plane1D "&#38;#38;#x1D">
</xsl:text>
</xsl:if>
<xsl:apply-templates select="key('set',@name)">
<xsl:sort lang="en" select="@id"/>
<xsl:sort lang="en" select="not(@optional)"/>
</xsl:apply-templates>
</xsl:result-document>
</xsl:if>
</xsl:template>
<xsl:template match="entity">
<xsl:variable name="a" select="string(../@id)"/>
<xsl:variable name="b" select="string(key('mml2',@id,$mml2)/@val)"/>
<xsl:variable name="n" select="@set"/>
<!--
<xsl:if test="not($a=$b) and $n=/unicode/entitygroups/group[@name='mathml']/set/@name">
<xsl:message>mathml2: <xsl:value-of select="@id,$a,$b"/></xsl:message>
</xsl:if>
-->
<xsl:variable name="ad" select="string(../@dec)"/>
<xsl:variable name="c" select="string(key('mml2',@id,$xhtml1)/@dec)"/>
<!--
<xsl:if test="not($ad=$c) and $n=/unicode/entitygroups/group[@name='xhtml1']/set/@name">
<xsl:message>xhtml1: <xsl:value-of select="@id,$ad,$c"/></xsl:message>
</xsl:if>
-->
<xsl:variable name="m" select="key('m',@id,$mathmap)/@hex"/>
<!--
<xsl:if test="exists($m) and not($a=$m)">
<xsl:message>unicode tr: <xsl:value-of select="@id,',',$a,',',$m"/></xsl:message>
</xsl:if>
-->
<!--
<xsl:if test="../unicodedata/@decomp[not(contains(.,'<'))]">
<xsl:message>DECOMP: <xsl:value-of select="@id,../@id,':',../unicodedata/@decomp"/></xsl:message>
</xsl:if>
-->
<xsl:if test="@optional">
<xsl:text/><!ENTITY % <xsl:value-of select="@optional"/> "<xsl:value-of select="@default"/>"> <xsl:text/>
<xsl:text/><![%<xsl:value-of select="@optional"/>;[<xsl:text/>
</xsl:if>
<xsl:if test="../description/@unicode='none'"><!--</xsl:if>
<xsl:text><!ENTITY </xsl:text>
<xsl:value-of select="@id"/>
<xsl:value-of select="substring(' ',string-length(@id))"/>
<xsl:text> "</xsl:text>
<xsl:choose>
<xsl:when test="'60' = ../@dec or '38' = ../@dec">
<xsl:text>&#38;#</xsl:text><xsl:value-of select="../@dec"/>
</xsl:when>
<xsl:when test="$plane1hack and starts-with(../@id,'U1D')">
<xsl:text>%plane1D;</xsl:text><xsl:value-of select="substring(../@id,4)"/>
</xsl:when>
<xsl:when test="starts-with(../description,'COMBINING') and $guard-combining">
<xsl:text> &#x</xsl:text><xsl:value-of select="substring(../@id,2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text/>&<xsl:if test="starts-with(../@dec,'60-')">#38;</xsl:if>#x<xsl:text/>
<xsl:value-of select="replace(translate(../@id,'Ux',''),'-',';&#x')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>;" ></xsl:text>
<xsl:if test="../description/@unicode='none'"> --></xsl:if>
<xsl:text><!--</xsl:text>
<xsl:value-of select="desc[$olddesc]|../description[not($olddesc)]"/>
<xsl:if test="../description/@unicode='provisional'"> --><!-- (Provisional)</xsl:if>
<xsl:text> --></xsl:text>
<xsl:if test="@optional">
<xsl:text>]]></xsl:text>
</xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:key name="set" match="entity" use="@set"/>
<xsl:key name="m" match="c" use="@id"/>
<xsl:template match="/">
<xsl:apply-templates select="unicode/entitygroups/group[@name='2007']"/>
</xsl:template>
<xsl:template match="charlist"/>
<xsl:template match="group[@name='2007']">
<xsl:result-document method="text" href="2007/w3centities.ent">
<xsl:call-template name="preamble">
<xsl:with-param name="name" select="'Combined Set'"/>
<xsl:with-param name="file" select="'w3centities'"/>
<xsl:with-param name="write-file" select="false()"/>
</xsl:call-template>
<xsl:apply-templates select="set"/>
</xsl:result-document>
<xsl:result-document method="text" href="2007/w3centities-f.ent">
<xsl:call-template name="preamble">
<xsl:with-param name="name" select="'Combined Set'"/>
<xsl:with-param name="file" select="'w3centities-f'"/>
<xsl:with-param name="write-file" select="true()"/>
</xsl:call-template>
<xsl:for-each-group select="key('set',set/@name)" group-by="@id">
<xsl:sort select="@id"/>
<xsl:apply-templates select="."/>
</xsl:for-each-group>
</xsl:result-document>
<xsl:result-document method="text" href="2007/htmlmathml.ent">
<xsl:call-template name="preamble">
<xsl:with-param name="name" select="'HTML MathML Set'"/>
<xsl:with-param name="file" select="'htmlmathml'"/>
<xsl:with-param name="write-file" select="false()"/>
</xsl:call-template>
<xsl:apply-templates select="../group[@name='html5']/set">
<xsl:with-param name="write-file" select="false()"/>
</xsl:apply-templates>
<xsl:apply-templates select="../group[@name='mathml']/set">
<xsl:with-param name="write-file" select="false()"/>
</xsl:apply-templates>
</xsl:result-document>
<xsl:result-document method="text" href="2007/htmlmathml-f.ent">
<xsl:call-template name="preamble">
<xsl:with-param name="name" select="'HTML MathML Set'"/>
<xsl:with-param name="file" select="'htmlmathml-f'"/>
<xsl:with-param name="write-file" select="true()"/>
</xsl:call-template>
<xsl:for-each-group select="key('set',../group[@name=('mathml','html5')]/set/@name)" group-by="@id">
<xsl:sort select="@id"/>
<xsl:apply-templates select="."/>
</xsl:for-each-group>
</xsl:result-document>
<xsl:result-document method="text" href="2007/htmlmathml.json">
<xsl:text> {</xsl:text>
<xsl:text> "characters": {</xsl:text>
<xsl:for-each-group select="key('set',../group[@name=('mathml','html5')]/set/@name)" group-by="@id">
<xsl:sort select="@id"/>
<xsl:if test="position()!=1">,</xsl:if>
<xsl:text> </xsl:text>
<xsl:apply-templates select="." mode="json"/>
</xsl:for-each-group>
<xsl:text> },</xsl:text>
<xsl:text> "optional-;": [</xsl:text>
<xsl:for-each-group select="key('set',../group[@name=('mathml','html5')]/set/@name)[@optional-semi]" group-by="@id">
<xsl:sort select="@id"/>
<xsl:if test="position()!=1">, </xsl:if>
<xsl:value-of select="concat('"',@id,'"')"/>
</xsl:for-each-group>
<xsl:text>]</xsl:text>
<xsl:text> } </xsl:text>
</xsl:result-document>
</xsl:template>
<xsl:template match="group[@name='predefined']"/>
<xsl:template match="group[@name='mathml']">
<xsl:apply-templates select="set[starts-with(@name,'m')]"/>
</xsl:template>
<xsl:template name="preamble">
<xsl:param name="name"/>
<xsl:param name="file"/>
<xsl:param name="write-file"/>
<!--
Copyright 1998 - 2016 W3C.
Use and distribution of this code are permitted under the terms of
either of the following two licences:
1) W3C Software Notice and License.
http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html
2) The license used for the WHATWG HTML specification,
which states, in full:
You are granted a license to use, reproduce and create derivative
works of this document.
Please report any errors to David Carlisle
via the public W3C list www-math@w3.org.
<xsl:choose>
<xsl:when test="$name='HTML MathML Set'">
Public identifier: web-entities
Public identifier: -//W3C//ENTITIES HTML MathML Set//EN//XML
System identifier: http://www.w3.org/2003/entities/2007/htmlmathml-f.ent
One of the public identifiers should always be used verbatim.
(The first one is more suitable for XHTML, the second one uses
Formal Public Identifier syntax, that may be required by SGML systems.)
The system identifier may be changed to suit local requirements.
Typical invocations:
<!ENTITY % htmlmathml-f PUBLIC
"-//W3C//ENTITIES HTML MathML Set//EN//XML"
"http://www.w3.org/2003/entities/2007/htmlmathml-f.ent"
>
%<xsl:value-of select="$file"/>;
<DOCTYPE html PUBLIC "web-entities"
"http://www.w3.org/2003/entities/2007/htmlmathml-f.ent"
>
</xsl:when>
<xsl:otherwise>
Public identifier: -//W3C//ENTITIES <xsl:value-of select="$name"/>//EN//XML
System identifier: http://www.w3.org/2003/entities/2007/<xsl:value-of select="$file"/>.ent
The public identifier should always be used verbatim.
The system identifier may be changed to suit local requirements.
Typical invocation:
<!ENTITY % <xsl:value-of select="$file"/> PUBLIC
"-//W3C//ENTITIES <xsl:value-of select="$name"/>//EN//XML"
"http://www.w3.org/2003/entities/2007/<xsl:value-of select="$file"/>.ent"
>
%<xsl:value-of select="$file"/>;
</xsl:otherwise>
</xsl:choose>
<xsl:if test="false() and $write-file">
Some entity names in this file are derived from files carrying the
following notices:
(C) International Organization for Standardization 1986,1991
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
</xsl:if>
-->
</xsl:template>
<xsl:template match="entity" mode="json">
<xsl:variable name="a" select="string(../@id)"/>
<xsl:variable name="b" select="string(key('mml2',@id,$mml2)/@val)"/>
<xsl:variable name="n" select="@set"/>
<xsl:variable name="ad" select="string(../@dec)"/>
<xsl:variable name="c" select="string(key('mml2',@id,$xhtml1)/@dec)"/>
<xsl:variable name="m" select="key('m',@id,$mathmap)/@hex"/>
<xsl:if test="../description/@unicode='none'"><!--</xsl:if>
<xsl:text>"</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>": "</xsl:text>
<xsl:choose>
<xsl:when test="not(starts-with(../@id,'U0'))">
<xsl:variable name="n" select="number(replace(../@dec,'-.*','')) - 65536"/>
<xsl:text>\u</xsl:text>
<xsl:value-of select="d:dtoh(($n idiv 1024) + 55296)"/>
<xsl:text>\u</xsl:text>
<xsl:value-of select="d:dtoh(($n mod 1024) + 56320)"/>
<xsl:if test="contains(../@dec,'-')">
<xsl:text>!!!!!!</xsl:text>
<xsl:message select="../@dec"/>
<xsl:value-of select="../@dec"/>
</xsl:if>
</xsl:when>
<xsl:when test="starts-with(../description,'COMBINING')">
<xsl:text> \u</xsl:text><xsl:value-of select="substring(../@id,3)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="replace(../@id,'[U\-]0','\\u')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:variable name="hexd" select="('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','0')"/>
<xsl:function name="d:dtoh">
<xsl:param name="d"/>
<xsl:value-of select="if($d gt 16) then d:dtoh($d idiv 16) else '',$hexd[1+($d mod 16)]" separator=""/>
</xsl:function>
</xsl:stylesheet>