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
/
unicodedata.xsl
269 lines (241 loc) · 9.88 KB
/
unicodedata.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
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="data:,dpc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="d xs">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" encoding="US-ASCII" omit-xml-declaration="yes"/>
<!--
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-5.1.0d10.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-5.2.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-6.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-p.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-6.1.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-6.2.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-6.3.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-7.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-8.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-9.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-10.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-11.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-12.0.0.txt'),'[ ]+')"/>
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-12.1.0.txt'),'[ ]+')"/>
-->
<xsl:variable name="UD" select="tokenize(unparsed-text('UnicodeData-13.0.0.txt'),'[ ]+')"/>
<xsl:variable name="uc" select="doc('unicode.xml')"/>
<xsl:variable name="comb" select="doc('combine.xml')"/>
<!--
<xsl:variable name="MC" select="'MathClass-11.txt'"/>
<xsl:variable name="MC" select="'MathClass-13.txt'"/>
-->
<xsl:variable name="MC" select="'MathClass-15.txt'"/>
<xsl:variable name="mathclass">
<xsl:for-each select="tokenize(unparsed-text($MC),'[ ]+')[matches(.,'^[0-9A-F.]+;[A-Z]')]">
<mc c="{substring-before(.,';')}"><xsl:value-of select="substring-after(.,';')"/></mc>
</xsl:for-each>
</xsl:variable>
<xsl:key name="mathclass" match="mc" use="if(contains(@c,'..'))
then
(d:hexs(substring-before(@c,'..')) to d:hexs(substring-after(@c,'..')))
else
d:hexs(@c)
"/>
<xsl:key name="char" match="character" use="@id"/>
<xsl:template name="main">
<xsl:result-document href="uc-new.xml">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="unicode.xsl"</xsl:processing-instruction>
<xsl:text> </xsl:text>
<xsl:copy-of select="$uc/comment()"/>
<xsl:text> </xsl:text>
<unicode>
<xsl:copy-of select="$uc/unicode/(@*,node() except charlist)"/>
<charlist>
<xsl:perform-sort>
<xsl:sort select="@id"/>
<xsl:sequence select="$uc/unicode/charlist/character"/>
<xsl:for-each select="$UD">
<xsl:analyze-string select="." regex="^([^;]*);([A-Z][^;]*);([^;]*);.*">
<xsl:matching-substring>
<!--
<xsl:message>
<xsl:value-of select="position(),'===',.,concat('U',if(string-length(regex-group(1))=4) then '0' else '',regex-group(1))"/>
</xsl:message>
-->
<xsl:if test="not(key('char',concat('U',if(string-length(regex-group(1))=4) then '0' else '',regex-group(1)),$uc))">
<character id="{concat('U',if(string-length(regex-group(1))=4) then '0' else '',regex-group(1))}"
dec="{d:hexs(regex-group(1))}"
image="none">
<unicodedata>
<xsl:variable name="u" select="tokenize(.,';')"/>
<xsl:for-each select="$udfields">
<xsl:variable name="p" select="position()"/>
<xsl:if test="$p gt 2 and $u[$p]">
<xsl:attribute name="{.}" select="$u[$p]"/>
</xsl:if>
</xsl:for-each>
<xsl:message select="'@@',."/>
<xsl:if test="key('mathclass',d:hexs(.),$mathclass)">
<xsl:attribute name="mathclass" select="key('mathclass',d:hexs(.),$mathclass)"/>
</xsl:if>
</unicodedata>
<description unicode="proposed"><xsl:value-of select="regex-group(2)"/></description>
</character>
</xsl:if>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:perform-sort>
</charlist>
</unicode>
</xsl:result-document>
</xsl:template>
<xsl:variable name="udfields" select="('code',
'name','category','combclass','bidi','decomp','decimal','digit','numeric','mirror','unicode1','comment','upper','lower','title')"/>
<xsl:function name="d:hex" as="xs:integer">
<xsl:param name="x"/>
<xsl:sequence
select="if (empty($x)) then 0 else ($x[last()] + 16* d:hex($x[position()!=last()]))"/>
</xsl:function>
<xsl:function name="d:hexs">
<xsl:param name="x"/>
<xsl:sequence select="d:hex(
for $i in string-to-codepoints($x)
return if ($i > 64) then $i - 55 else $i - 48)"/>
</xsl:function>
<xsl:variable name="hexd" select="('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="'000',$hexd[$d idiv 16],$hexd[$d mod 16]" separator=""/>
</xsl:function>
<xsl:template name="mathclass">
<xsl:result-document href="uc-new.xml">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="unicode.xsl"</xsl:processing-instruction>
<xsl:text> </xsl:text>
<xsl:copy-of select="$uc/comment()"/>
<xsl:text> </xsl:text>
<xsl:apply-templates mode="mathclass" select="$uc/*"/>
</xsl:result-document>
</xsl:template>
<xsl:template mode="mathclass" match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="mathclass"/>
</xsl:copy>
</xsl:template>
<xsl:template mode="mathclass" match="unicodedata[@category]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:if test="key('mathclass',xs:integer(../@dec),$mathclass)">
<xsl:attribute name="mathclass" select="key('mathclass',xs:integer(../@dec),$mathclass)[1]"/>
</xsl:if>
<xsl:if test="key('mathclass',xs:integer(../@dec),$mathclass)[2]">
<xsl:message select="key('mathclass',xs:integer(../@dec),$mathclass)"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<!-- -->
<xsl:variable name="umt">
<umd>
<xsl:for-each select="tokenize(unparsed-text('https://raw.githubusercontent.com/wspr/unicode-math/master/unicode-math-table.tex'),
'[ ]+')[contains(.,'UnicodeMathSymbol')]">
<xsl:variable name="id" select="replace(.,'.UnicodeMathSymbol\{"([0-9A-F]+)\}.*','$1')"/>
<character id="U{if(string-length($id)=4) then '0' else ''}{$id}">
<xsl:value-of select="replace(.,'.UnicodeMathSymbol\{"([0-9A-F]+)\}\{(\\[^{} ]+).*','$2')"/>
</character>
</xsl:for-each>
</umd>
</xsl:variable>
<xsl:template name="unicode-math">
<xsl:result-document href="uc-new.xml">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="unicode.xsl"</xsl:processing-instruction>
<xsl:text> </xsl:text>
<xsl:copy-of select="$uc/comment()"/>
<xsl:text> </xsl:text>
<unicode>
<xsl:copy-of select="$uc/unicode/(@*,node() except charlist)"/>
<charlist>
<xsl:for-each select="$uc/unicode/charlist/character">
<character>
<xsl:copy-of select="@*,unicodedata,afii,latex,mathlatex[not(@set='unicode-math')]"/>
<xsl:if test="key('char',@id,$umt)">
<mathlatex set="unicode-math">
<xsl:value-of select="key('char',@id,$umt)"/>
</mathlatex>
</xsl:if>
<xsl:copy-of select="* except (unicodedata,afii,latex,mathlatex)"/>
</character>
</xsl:for-each>
</charlist>
</unicode>
</xsl:result-document>
</xsl:template>
<xsl:template name="opdict">
<xsl:result-document href="uc-new.xml">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="unicode.xsl"</xsl:processing-instruction>
<xsl:text> </xsl:text>
<xsl:copy-of select="$uc/comment()"/>
<xsl:text> </xsl:text>
<unicode>
<xsl:copy-of select="$uc/unicode/(@*,node() except charlist)"/>
<charlist>
<xsl:for-each select="$uc/unicode/charlist/character">
<character>
<xsl:copy-of select="@*,* except description"/>
<xsl:variable name="u" select="substring(@id,2)"/>
<xsl:variable name="b" select="
/unicode/unicodeblocks/block[
@start le $u and @end ge $u]/string(@name)"/>
<xsl:choose>
<xsl:when test="'023F9' le $u and '02767' ge $u"/>
<xsl:when test="not(operator-dictionary) and number(@dec)
and
$b=(
'Mathematical Operators',
'Supplemental Mathematical Operators',
'Miscellaneous Technical',
'Miscellaneous Symbols',
'Miscellaneous Symbols and Arrows',
'Dingbats'
)
and
not(contains(description,'ARROW'))
">
<xsl:message select="$b,string(@id), 999, description/string(@unicode), string(description)"/>
<operator-dictionary form="prefix" lspace="5" rspace="5" priority="999"/>
</xsl:when>
<xsl:when test="not(operator-dictionary) and number(@dec)
and
$b=(
'Mathematical Operators',
'Supplemental Mathematical Operators',
'Miscellaneous Technical',
'Miscellaneous Symbols',
'Miscellaneous Symbols and Arrows',
'Dingbats'
)
and
(contains(description,'ARROW'))
">
<xsl:message select="$b,string(@id), 270, description/string(@unicode), string(description)"/>
<operator-dictionary form="infix" lspace="5" rspace="5" priority="270"/>
</xsl:when>
<xsl:when test="not(operator-dictionary) and number(@dec)
and
$b=(
'Arrows',
'Supplemental Arrows-A',
'Supplemental Arrows-B',
'Supplemental Arrows-C'
)
">
<xsl:message select="$b,string(@id), 270, description/string(@unicode), string(description)"/>
<operator-dictionary form="infix" lspace="5" rspace="5" priority="270"/>
</xsl:when>
</xsl:choose>
<xsl:copy-of select="description"/>
</character>
</xsl:for-each>
</charlist>
</unicode>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>