-
Notifications
You must be signed in to change notification settings - Fork 0
/
flextext2glosshtml.xsl
192 lines (153 loc) · 7.8 KB
/
flextext2glosshtml.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="http://www.philol.msu.ru/~languedoc/xml"
exclude-result-prefixes="#all" version="2.0">
<!-- Modified after Sasha Arkhipov's stylesheet:
https://github.com/sarkipo/xsl4interlinear
Uses Leipzig.js which can be found here:
http://bdchauvette.net/leipzig.js/
https://github.com/bdchauvette/leipzig.js/
-->
<xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="no"/>
<xsl:namespace-alias stylesheet-prefix="#default" result-prefix=""/>
<xsl:template match="interlinear-text/item[@type='title-abbreviation']">
<xsl:variable name="filename" select="concat('html/',text(),'.html')"/>
<xsl:variable name="html_break">
<br/>
</xsl:variable>
<xsl:result-document href="{$filename}">
<html>
<head>
<link rel="stylesheet" href="../leipzig.min.css"/>
<script src="../leipzig.min.js"/>
<style>
@font-face{
font-family:"Charis SIL";
src:url("fonts/CharisSILCompact-R.ttf") format('truetype');
}
@font-face{
font-family:"Charis SIL";
src:url("fonts/CharisSILCompact-B.ttf") format('truetype');
font-weight:bold;
}
@font-face{
font-family:"Charis SIL";
src:url("fonts/CharisSILCompact-BI.ttf") format('truetype');
font-weight:bold;
font-style:italic;
}
@font-face{
font-family:"Charis SIL";
src:url("fonts/CharisSILCompact-I.ttf") format('truetype');
font-style:italic;
}
div{
font-family:"Charis SIL";
/* line-height: 12pt; This can be used to control the line height */
}
}
p{
font-family:"Charis SIL";
}</style>
</head>
<body>
<h2>
<xsl:value-of
select="preceding-sibling::node()[@type='title' and @lang='en']"/>
</h2>
<p>
<xsl:analyze-string select="following-sibling::node()[@type='source' and @lang='en']" regex="/">
<xsl:matching-substring>
<br />
<xsl:value-of select="'
'" />
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</p>
<xsl:for-each select="../paragraphs/paragraph/phrases/phrase">
<div>
<xsl:attribute name="data-gloss"/>
<p>
<xsl:for-each-group select="./words/word"
group-starting-with="word[item/@type!='punct' and preceding-sibling::word/item/@type!='punct']">
<xsl:variable name="value">
<xsl:value-of
select="current-group()/item[@type='txt' or @type='punct']"
separator=""/>
</xsl:variable>
<xsl:value-of select="my:cleanup-tx($value)"/>
</xsl:for-each-group>
</p>
<!-- This adds the segmented word elements -->
<p>
<xsl:for-each-group select=".//word"
group-starting-with="word[item/@type!='punct' and preceding-sibling::word/item/@type!='punct']">
<xsl:variable name="value">
<xsl:value-of
select="current-group()/morphemes/morph/item[@type='cf' and @lang='sel']"
separator=""/>
</xsl:variable>
<xsl:value-of select="my:cleanup-tx($value)"/>
</xsl:for-each-group>
</p>
<!-- This adds the glosses -->
<p>
<xsl:for-each-group select=".//word"
group-starting-with="word[item/@type!='punct' and preceding-sibling::word/item/@type!='punct']">
<xsl:variable name="value">
<xsl:value-of
select="current-group()/morphemes/morph/item[@type='gls' and @lang='en']"
separator="-"/>
</xsl:variable>
<xsl:value-of select="my:cleanup-tx($value)"/>
</xsl:for-each-group>
</p>
<!-- This adds the translation -->
<xsl:for-each select="./item[@type='gls' and @lang='en']">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
</div>
</xsl:for-each>
<script src="leipzig.min.js"/>
<script>
document.addEventListener('DOMContentLoaded', function() {
Leipzig({ firstLineOrig: true }).gloss();
});
</script>
<hr/>
<p>Glosses visualized with <a href="http://bdchauvette.net/leipzig.js/"
>Leipzig.js</a>.</p>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:function name="my:cleanup-tx" as="xs:string">
<xsl:param name="in" as="xs:string"/>
<xsl:value-of select="concat($in,' ')"/>
<!-- attach one space -->
</xsl:function>
<xsl:function name="my:cleanup-morph" as="xs:string">
<xsl:param name="in" as="xs:string"/>
<xsl:value-of select="replace($in,'-\^0$','')"/>
<!-- strip final -^0 -->
</xsl:function>
<xsl:function name="my:cleanup-gloss" as="xs:string">
<xsl:param name="in" as="xs:string"/>
<xsl:value-of select="replace($in,'-(\[.+\])','.$1')"/>
<!-- put . instead of - before [...] -->
</xsl:function>
<xsl:function name="my:cleanup-gloss-tokens" as="xs:string">
<xsl:param name="in" as="xs:string"/>
<xsl:value-of select="replace($in,' -','-')"/>
<!-- tries to put things together -->
</xsl:function>
<xsl:function name="my:cleanup-gloss-glosses" as="xs:string">
<xsl:param name="in" as="xs:string"/>
<xsl:value-of select="replace($in,' -','-')"/>
<!-- tries to put things together -->
</xsl:function>
</xsl:stylesheet>