-
Notifications
You must be signed in to change notification settings - Fork 0
/
cte3.xsl
219 lines (199 loc) · 7.34 KB
/
cte3.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
<xsl:stylesheet
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output omit-xml-declaration="1" />
<xsl:variable name="Fonts" select="//*:Fonts"/>
<xsl:template match="*:cte">
<TEI>
<teiHeader>
<titleStmt>
<xsl:apply-templates select="//*:HeaderFooter/*:ab[string-length(normalize-space()) gt 0]" />
</titleStmt>
</teiHeader>
<xsl:apply-templates />
</TEI>
</xsl:template>
<xsl:template match="*:HeaderFooter/tei:ab">
<title>
<xsl:apply-templates />
</title>
</xsl:template>
<xsl:template match="*:Text">
<text>
<body>
<xsl:apply-templates />
</body>
</text>
</xsl:template>
<xsl:template match="*:C">
<hi>
<xsl:apply-templates select="@vals" />
<xsl:apply-templates />
</hi>
</xsl:template>
<xsl:template match="*:F">
<xsl:variable name="rendition">
<xsl:if test="matches(@type, '^P\d+')">
<xsl:variable name="num" select="substring(@type, 2)" />
<xsl:value-of select="//*:fdef[@n = $num]/@name" />
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="string-length($rendition) gt 0 or @vals">
<hi>
<xsl:apply-templates select="@vals" />
<xsl:if test="string-length($rendition) gt 0">
<xsl:attribute name="rendition" select="'#' || $rendition" />
</xsl:if>
<xsl:apply-templates select="node()" />
</hi>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*:F/text()">
<!-- there should now only be text in here -->
<xsl:choose>
<xsl:when test="not(parent::*/preceding-sibling::node()) and matches(., '^\s')">
<xsl:value-of select="replace(., '^\s+', '')"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- O = outer margin (I = inner margin) ? -->
<xsl:template match="*:O">
<note place="outer-margin">
<xsl:apply-templates />
</note>
</xsl:template>
<xsl:template match="tei:ptr">
<ptr>
<xsl:sequence select="@*" />
<xsl:if test="not(@corresp)">
<xsl:variable name="type" select="@type" />
<xsl:attribute name="position" select="count(preceding::tei:ptr[@type = $type and not(@corresp)]) + 1" />
</xsl:if>
</ptr>
</xsl:template>
<xsl:template match="@vals">
<xsl:variable name="styles" as="xs:string*">
<xsl:apply-templates select="." mode="eval" />
</xsl:variable>
<xsl:attribute name="style">
<xsl:value-of select="string-join($styles, '; ') "/>
<xsl:text>;</xsl:text>
</xsl:attribute>
</xsl:template>
<xsl:template match="@vals" mode="eval">
<xsl:for-each select="tokenize(., '\|')">
<xsl:choose>
<xsl:when test=". eq ''" />
<xsl:when test="matches(., 'P\d')"/>
<xsl:when test="matches(., 'g\d')">
<xsl:variable name="num" select="substring(., 2)"/>
<xsl:variable name="font" select="normalize-space($Fonts/*:Font[@num = $num]/@name)" />
<xsl:value-of select="'font-family: ' || $font"/>
</xsl:when>
<!-- font variations -->
<xsl:when test=". eq 'i+'">
<xsl:text>font-style: italic</xsl:text>
</xsl:when>
<xsl:when test=". eq 'b+'">
<xsl:text>font-weight: bold</xsl:text>
</xsl:when>
<xsl:when test=". eq 'k+'">
<xsl:text>font-variant: smallCaps</xsl:text>
</xsl:when>
<xsl:when test=". eq 'u0'">
<xsl:text>font-decoration: underline</xsl:text>
</xsl:when>
<!-- font size, line height, spacing, ... -->
<xsl:when test="matches(., 's\d+')">
<xsl:variable name="num" select="number(substring(., 2)) div 10" />
<xsl:value-of select="'font-size: ' || $num || 'pt'" />
</xsl:when>
<xsl:when test="matches(., 'w\-?\d+')">
<xsl:variable name="num">
<xsl:analyze-string select="." regex="w(-?)(\d+)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)" />
<xsl:value-of select="number(regex-group(2)) div 10" />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="'letter-spacing: ' || $num || 'pt'"/>
</xsl:when>
<xsl:when test="matches(., 'L\-?\d+')">
<xsl:variable name="num">
<xsl:analyze-string select="." regex="L-?(\d+)">
<xsl:matching-substring>
<xsl:value-of select="number(regex-group(1 )) div 10" />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="'line-height: ' || $num || 'pt'"/>
</xsl:when>
<xsl:when test=". eq 'c+'">
<xsl:text>text-transform: uppercase</xsl:text>
</xsl:when>
<!-- margins -->
<xsl:when test="substring(., 1, 2) eq 'SA'">
<xsl:value-of select="'margin-bottom: ' || number(substring(., 3)) div 10 || 'pt'" />
</xsl:when>
<xsl:when test="substring(., 1, 2) eq 'SB'">
<xsl:value-of select="'margin-top: ' || number(substring(., 3)) div 10 || 'pt'" />
</xsl:when>
<xsl:when test="substring(., 1, 2) eq 'ML'">
<xsl:value-of select="'margin-left: ' || number(substring(., 3)) div 10 || 'pt'" />
</xsl:when>
<!-- positioning -->
<xsl:when test="substring(., 1, 1) eq 'I'">
<xsl:variable name="num">
<xsl:analyze-string select="." regex="I(-?)(\d+)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)" />
<xsl:value-of select="number(regex-group(2)) div 10" />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="'text-indent: ' || $num || 'pt'"/>
</xsl:when>
<!-- alignment -->
<xsl:when test=". eq 'AB'">
<xsl:text>text-align: justify</xsl:text>
</xsl:when>
<xsl:when test=". eq 'AC'">
<xsl:text>text-align: center</xsl:text>
</xsl:when>
<xsl:when test=". eq 'AD'">
<xsl:text>text-align: justify; text-align-last: center</xsl:text>
</xsl:when>
<!-- directives to be ignored for now -->
<!-- TL: tab stops;
RIS(B): unknown
ROF: unknown
-->
<xsl:when test="substring(., 1, 1) = ('B', 'C', 'K', 'N')" />
<xsl:when test="substring(., 1, 2) = ('MR', 'TL', 'WO', 'WW', 'G0')" />
<xsl:when test="substring(., 1, 3) = ('RIS', 'RIU', 'ROF', 'ROS', 'ROU')" />
<!-- fallback -->
<xsl:otherwise>
<xsl:sequence select="translate(., '+>', '')" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>