blob: 5a486c0809d11d99ac8449088adddaad8eaa1e34 [file] [log] [blame]
Akron9a8ee3e2022-01-31 13:51:49 +01001<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
bansp5e2d1c02022-03-10 04:51:40 +01003 xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:nkjp="http://www.nkjp.pl/ns/1.0"
4 xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:f="func"
5 xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs f map nkjp tei"
6 version="3.0" expand-text="yes">
Akron9a8ee3e2022-01-31 13:51:49 +01007
bansp5e2d1c02022-03-10 04:51:40 +01008 <xsl:param name="corpusID" as="xs:string"/>
9 <xsl:param name="docID" as="xs:string"/>
10 <xsl:param name="textID" as="xs:string"/>
11
12 <xsl:param name="sourceDir" select="'test/resources/nkjp2korap_sample1/KOT/'" as="xs:string"/>
banspf79443e2022-02-25 14:25:33 +010013 <!-- the select is a fallback, so that it's clear to the reviewer what I'm passing in the param -->
Akron9a8ee3e2022-01-31 13:51:49 +010014
bansp5e2d1c02022-03-10 04:51:40 +010015 <xsl:variable name="targetTextDir"
16 select="'test/output/' || $corpusID || '/' || $docID || '/' || $textID || '/'" as="xs:string"/>
17 <xsl:variable name="targetCorpusDir" select="'test/output/' || $corpusID || '/'" as="xs:string"/>
18
19 <xsl:variable name="systemDoctypeI5"
bansp97ba7ce2022-03-26 05:14:06 +010020 select="'http://corpora.ids-mannheim.de/I5/DTD/i5.dtd'" as="xs:string"
bansp5e2d1c02022-03-10 04:51:40 +010021 static="true"/>
22
bansp97ba7ce2022-03-26 05:14:06 +010023 <xsl:variable name="publicDoctypeI5" select="'-//IDS//DTD I5 1.0//EN'" as="xs:string"
bansp5e2d1c02022-03-10 04:51:40 +010024 static="true"/>
25
26 <xsl:variable name="KorAP_namespace" select="'http://ids-mannheim.de/ns/KorAP'" static="true"
27 as="xs:string"/>
28
bansp5f841732022-03-16 06:27:31 +010029 <xsl:variable name="KorAP-XML_version" select="'KorAP-0.4'" as="xs:string" static="true"/>
30 <!-- this is only a bit funny -->
31
32 <xsl:variable name="compoundID" as="xs:string"
33 select="$corpusID || '_' || $docID || '.' || $textID"/>
34 <!-- this is what occurs in the text and data layers as @docid -->
bansp5e2d1c02022-03-10 04:51:40 +010035
36 <xsl:mode name="corpus" on-no-match="deep-skip"/>
37 <xsl:mode name="text" on-no-match="deep-skip"/>
bansp9103aab2022-03-19 05:10:21 +010038 <xsl:mode name="header-text" on-no-match="text-only-copy"/>
bansp5e2d1c02022-03-10 04:51:40 +010039
bansp5f841732022-03-16 06:27:31 +010040 <!-- <xsl:variable name="text_depth" as="xs:integer" select="xs:integer('2')" static="true"/>
41 <!-\- this magic number indicates the depth of the <TEI> element inside teiCorpus/TEI -\->
42-->
43 <xsl:function name="f:compute_nesting" as="xs:integer">
44 <xsl:param name="node" as="node()"/>
45 <xsl:variable name="rel_depth"
46 select="count($node/ancestor-or-self::*[local-name(.) ne 'TEI'][local-name(.) ne 'teiCorpus'])"
47 as="xs:integer"/>
48<!-- I think my skills are lacking -->
49 <xsl:sequence select="$rel_depth"/>
50 </xsl:function>
51
52 <xsl:function name="f:calc_content_length" as="xs:integer">
53 <xsl:param name="node" as="node()"/>
54 <xsl:choose>
55 <xsl:when test="$node/self::tei:text or $node/self::tei:body">
56 <xsl:variable name="last_corresp"
57 select="$node/descendant::tei:p[last()]/descendant::tei:s[last()]/descendant::tei:seg[last()]/attribute::corresp"
58 as="attribute(corresp)"/>
59 <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/>
60 <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/>
61 </xsl:when>
62 <xsl:when test="$node/self::tei:p">
63 <xsl:variable name="last_corresp"
64 select="$node/descendant::tei:s[last()]/descendant::tei:seg[last()]/attribute::corresp"
65 as="attribute(corresp)"/>
66 <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/>
67 <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/>
68 </xsl:when>
69 <xsl:when test="$node/self::tei:s">
70 <xsl:variable name="last_corresp"
71 select="$node/descendant::tei:seg[last()]/attribute::corresp"
72 as="attribute(corresp)"/>
73 <xsl:variable name="numbers" select="substring-after(substring-before($last_corresp,')'),',')"/>
74 <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/>
75 </xsl:when>
76 <xsl:otherwise>
77 <xsl:variable name="numbers" select="substring-after(substring-before($node/@corresp,')'),',')"/>
78 <xsl:sequence select="xs:integer(substring-before($numbers,',')) + xs:integer(substring-after($numbers,','))"/>
79 </xsl:otherwise>
80 </xsl:choose>
81 </xsl:function>
bansp5e2d1c02022-03-10 04:51:40 +010082
bansp9103aab2022-03-19 05:10:21 +010083 <xsl:template match="@default" mode="#all"/>
bansp97ba7ce2022-03-26 05:14:06 +010084 <!-- this is to delete some auto-inserted attribute throughout -->
bansp9103aab2022-03-19 05:10:21 +010085
bansp5e2d1c02022-03-10 04:51:40 +010086 <xsl:template name="xsl:initial-template">
87 <xsl:variable name="text.xml" as="document-node()" select="doc($sourceDir || 'text.xml')"/>
bansp5f841732022-03-16 06:27:31 +010088 <xsl:variable name="ann_morphosyntax.xml" as="document-node()"
89 select="doc($sourceDir || 'ann_morphosyntax.xml')"/>
90 <xsl:variable name="ann_segmentation.xml" as="document-node()"
91 select="doc($sourceDir || 'ann_segmentation.xml')"/>
bansp5e2d1c02022-03-10 04:51:40 +010092
93 <xsl:call-template name="create_data">
94 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +010095 <xsl:with-param name="target" select="$targetTextDir || 'data.xml'" as="xs:string"/>
96 </xsl:call-template>
97
98 <xsl:call-template name="create_struct">
99 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
100 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
101 as="document-node()"/>
102 <xsl:with-param name="target" select="$targetTextDir || 'struct/structure.xml'" as="xs:string"
103 />
104 </xsl:call-template>
105
106 <xsl:call-template name="create_morpho">
107 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
bansp3e5b20c2022-03-18 20:22:31 +0100108 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
109 as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100110 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml"
111 as="document-node()"/>
112 <xsl:with-param name="target" select="$targetTextDir || 'nkjp/morpho.xml'" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100113 </xsl:call-template>
114
115 <xsl:call-template name="create_text_header">
116 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100117 <xsl:with-param name="target" select="$targetTextDir || 'header.xml'" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100118 </xsl:call-template>
119
120 <xsl:call-template name="create_corpus_header">
121 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100122 <xsl:with-param name="target" select="$targetCorpusDir || 'header.xml'" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100123 </xsl:call-template>
124 </xsl:template>
125
126 <!-- ************************** data.xml ******************* -->
127
128 <xsl:template name="create_data">
129 <xsl:param name="text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100130 <xsl:param name="target" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100131 <!-- create the data.xml file -->
132 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
bansp5f841732022-03-16 06:27:31 +0100133 xpath-default-namespace="{$KorAP_namespace}" href="{$target}">
bansp5e2d1c02022-03-10 04:51:40 +0100134
Akron9a8ee3e2022-01-31 13:51:49 +0100135 <xsl:processing-instruction name="xml-model">href=&quot;text.rng&quot; type=&quot;application/xml&quot; schematypens=&quot;http://relaxng.org/ns/structure/1.0&quot;</xsl:processing-instruction>
bansp5e2d1c02022-03-10 04:51:40 +0100136 <xsl:element name="raw_text" namespace="{$KorAP_namespace}">
bansp5f841732022-03-16 06:27:31 +0100137 <xsl:attribute name="docid" select="$compoundID"/>
bansp5e2d1c02022-03-10 04:51:40 +0100138 <xsl:element name="metadata" namespace="{$KorAP_namespace}">
139 <xsl:attribute name="file" select="'metadata.xml'"/>
140 </xsl:element>
141
142 <xsl:element name="text" namespace="{$KorAP_namespace}">
banspf79443e2022-02-25 14:25:33 +0100143 <xsl:value-of select="$text.xml//*[local-name() = 'ab']"/>
bansp5e2d1c02022-03-10 04:51:40 +0100144 </xsl:element>
Akron9a8ee3e2022-01-31 13:51:49 +0100145 </xsl:element>
banspf79443e2022-02-25 14:25:33 +0100146 </xsl:result-document>
Akron9a8ee3e2022-01-31 13:51:49 +0100147 </xsl:template>
148
bansp5f841732022-03-16 06:27:31 +0100149 <!-- ************************** struct ******************* -->
150
151 <xsl:template name="create_struct">
152 <xsl:param name="text.xml" as="document-node()"/>
153 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
154 <xsl:param name="target" as="xs:string"/>
155
156 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
157 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
158 <xsl:processing-instruction name="xml-model">href=&quot;span.rng&quot; type=&quot;application/xml&quot; schematypens=&quot;http://relaxng.org/ns/structure/1.0&quot;</xsl:processing-instruction>
159 <xsl:element name="layer" namespace="{$KorAP_namespace}">
160 <xsl:attribute name="docid" select="$compoundID"/>
161 <xsl:attribute name="version" select="$KorAP-XML_version"/>
162
163 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
164 <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/>
165 </xsl:element>
166 </xsl:element>
167 </xsl:result-document>
168 </xsl:template>
169
170 <xsl:template match="tei:*" mode="struct">
171 <xsl:param name="ini" as="xs:integer" required="no" select="0"/>
172 <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/>
173 <xsl:param name="index" as="xs:integer" required="no" select="1"/>
174 <!-- I have made a major mess here, but it works... it's so spread out
175 because I wanted to make sure to be able to look up the individual
bansp3e5b20c2022-03-18 20:22:31 +0100176 constituent values, should anything go wrong; optimization will come when it's worked against a larger dataset -->
bansp5f841732022-03-16 06:27:31 +0100177 <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
178 <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/>
179 <xsl:variable name="preceding-count" select="count($preceding)"/>
180 <xsl:variable name="outside-preceding-count" as="xs:integer">
181 <xsl:choose>
182 <xsl:when test="self::tei:s or self::tei:p">
183 <xsl:choose>
184 <xsl:when test="$preceding-count">
185 <xsl:sequence select="
186 sum(for $p in $preceding
187 return
188 count($p/descendant::*))"/>
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:sequence select="0"/>
192 </xsl:otherwise>
193 </xsl:choose>
194 </xsl:when>
195 <xsl:otherwise>
196 <xsl:sequence select="0"/>
197 </xsl:otherwise>
198 </xsl:choose>
199 </xsl:variable>
200 <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count"
201 as="xs:integer"/>
202
203 <xsl:variable name="start" as="xs:integer">
204 <xsl:choose>
205 <xsl:when test="self::tei:text or self::tei:body">
206 <xsl:sequence select="0"/>
207 </xsl:when>
208 <xsl:when test="self::tei:p">
209 <xsl:variable name="first_corresp"
210 select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp"
211 as="attribute(corresp)"/>
212 <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/>
213 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
214 </xsl:when>
215 <xsl:when test="self::tei:s">
216 <xsl:variable name="first_corresp"
217 select="descendant::tei:seg[1]/attribute::corresp"
218 as="attribute(corresp)"/>
219 <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/>
220 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
221 </xsl:when>
222 <xsl:when test="self::tei:seg">
223 <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/>
224 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
225 </xsl:when>
226 </xsl:choose>
227 </xsl:variable>
228 <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)">
229 </xsl:variable>
bansp3e5b20c2022-03-18 20:22:31 +0100230
bansp5f841732022-03-16 06:27:31 +0100231 <xsl:element name="span" namespace="{$KorAP_namespace}">
232 <xsl:attribute name="id" select="'s' || $my_index"/>
233 <xsl:attribute name="from" select="$start"/>
234 <xsl:attribute name="to" select="$end"/>
235 <xsl:attribute name="l" select="f:compute_nesting(.)"/>
236 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
bansp3e5b20c2022-03-18 20:22:31 +0100237 <xsl:attribute name="type" select="'struct'"></xsl:attribute> <!-- STRUCT vs. LEX -->
bansp5f841732022-03-16 06:27:31 +0100238 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
bansp3e5b20c2022-03-18 20:22:31 +0100239 <xsl:attribute name="name" select="'name'"/>
240 <xsl:value-of select="local-name()"/>
bansp5f841732022-03-16 06:27:31 +0100241 </xsl:element>
242 <xsl:if test="count(@*)">
243 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
244 <xsl:attribute name="name" select="'attr'"/>
245 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
246 <xsl:attribute name="type" select="'attr'"/>
247 <xsl:for-each select="@*">
248 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
249 <xsl:attribute name="name" select="local-name(.)"/>
250 <xsl:value-of select="."/>
251 </xsl:element>
252 </xsl:for-each>
253 </xsl:element>
254 </xsl:element>
255 </xsl:if>
256 </xsl:element>
257 </xsl:element>
258 <xsl:apply-templates mode="struct">
259 <xsl:with-param name="ini" select="$start" as="xs:integer"/>
260 <xsl:with-param name="fin" select="$end" as="xs:integer"/>
261 <xsl:with-param name="index" select="$my_index"/>
262 </xsl:apply-templates>
263 </xsl:template>
264
265 <!-- ************************** morpho ******************* -->
266
267 <xsl:template name="create_morpho">
268 <xsl:param name="text.xml" as="document-node()"/>
bansp3e5b20c2022-03-18 20:22:31 +0100269 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100270 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
271 <xsl:param name="target" as="xs:string"/>
272
273 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
274 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
275 <xsl:processing-instruction name="xml-model">href=&quot;span.rng&quot; type=&quot;application/xml&quot; schematypens=&quot;http://relaxng.org/ns/structure/1.0&quot;</xsl:processing-instruction>
bansp3e5b20c2022-03-18 20:22:31 +0100276 <xsl:element name="layer" namespace="{$KorAP_namespace}">
277 <xsl:attribute name="docid" select="$compoundID"/>
278 <xsl:attribute name="version" select="$KorAP-XML_version"/>
279
280 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
281 <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="morpho">
282 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/>
283 </xsl:apply-templates>
284 </xsl:element>
285 </xsl:element>
bansp5f841732022-03-16 06:27:31 +0100286 </xsl:result-document>
287 </xsl:template>
288
bansp3e5b20c2022-03-18 20:22:31 +0100289 <xsl:template match="tei:*" mode="morpho">
290 <xsl:param name="ini" as="xs:integer" required="no" select="0"/>
291 <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/>
292 <xsl:param name="index" as="xs:integer" required="no" select="1"/>
293 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
294 <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
295 <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/>
296 <xsl:variable name="preceding-count" select="count($preceding)"/>
297 <xsl:variable name="outside-preceding-count" as="xs:integer">
298 <xsl:choose>
299 <xsl:when test="self::tei:s or self::tei:p">
300 <xsl:choose>
301 <xsl:when test="$preceding-count">
302 <xsl:sequence select="
303 sum(for $p in $preceding
304 return
305 count($p/descendant::*))"/>
306 </xsl:when>
307 <xsl:otherwise>
308 <xsl:sequence select="0"/>
309 </xsl:otherwise>
310 </xsl:choose>
311 </xsl:when>
312 <xsl:otherwise>
313 <xsl:sequence select="0"/>
314 </xsl:otherwise>
315 </xsl:choose>
316 </xsl:variable>
317 <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count"
318 as="xs:integer"/>
319
320 <xsl:variable name="start" as="xs:integer">
321 <xsl:choose>
322 <xsl:when test="self::tei:text or self::tei:body">
323 <xsl:sequence select="0"/>
324 </xsl:when>
325 <xsl:when test="self::tei:p">
326 <xsl:variable name="first_corresp"
327 select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp"
328 as="attribute(corresp)"/>
329 <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/>
330 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
331 </xsl:when>
332 <xsl:when test="self::tei:s">
333 <xsl:variable name="first_corresp"
334 select="descendant::tei:seg[1]/attribute::corresp"
335 as="attribute(corresp)"/>
336 <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/>
337 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
338 </xsl:when>
339 <!--<xsl:when test="self::tei:seg">
340 <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/>
341 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
342 </xsl:when>-->
343 </xsl:choose>
344 </xsl:variable>
345 <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)">
346 </xsl:variable>
347
348 <xsl:apply-templates mode="morpho">
349 <xsl:with-param name="ini" select="$start" as="xs:integer"/>
350 <xsl:with-param name="fin" select="$end" as="xs:integer"/>
351 <xsl:with-param name="index" select="$my_index"/>
352 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/>
353 </xsl:apply-templates>
354 </xsl:template>
bansp5f841732022-03-16 06:27:31 +0100355
bansp3e5b20c2022-03-18 20:22:31 +0100356 <xsl:template match="tei:seg" mode="morpho">
357 <xsl:param name="ini" as="xs:integer" required="no" select="0"/>
358 <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/>
359 <xsl:param name="index" as="xs:integer" required="no" select="1"/>
360 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
361 <!-- I have made a major mess here, but it works... it's so spread out
362 because I wanted to make sure to be able to look up the individual
363 constituent values, should anything go wrong -->
364 <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
365 <xsl:variable name="my_id" select="@xml:id" as="xs:string"/>
366 <xsl:variable name="my_morph-seg" as="node()" select="$ann_morphosyntax.xml//tei:seg[substring-after(@corresp,'#') eq $my_id]"/>
367 <xsl:variable name="my_disamb" select="$my_morph-seg//tei:fs/tei:f[@name eq 'disamb']" as="node()"/>
368 <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/>
369 <xsl:variable name="my_choice-lex" select="$my_morph-seg//tei:f[@name eq 'interps']/tei:fs[@type eq 'lex'][descendant::tei:symbol[@xml:id eq $my_choice-id]]" as="node()"/>
370 <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/>
371 <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/>
372 <xsl:variable name="preceding-count" select="count($preceding)"/>
373 <xsl:variable name="outside-preceding-count" as="xs:integer">
374 <xsl:choose>
375 <xsl:when test="self::tei:s or self::tei:p">
376 <xsl:choose>
377 <xsl:when test="$preceding-count">
378 <xsl:sequence select="
379 sum(for $p in $preceding
380 return
381 count($p/descendant::*))"/>
382 </xsl:when>
383 <xsl:otherwise>
384 <xsl:sequence select="0"/>
385 </xsl:otherwise>
386 </xsl:choose>
387 </xsl:when>
388 <xsl:otherwise>
389 <xsl:sequence select="0"/>
390 </xsl:otherwise>
391 </xsl:choose>
392 </xsl:variable>
393 <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count"
394 as="xs:integer"/>
395
396 <xsl:variable name="start" as="xs:integer">
397 <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/>
398 <xsl:sequence select="xs:integer(substring-before($numbers,','))"/>
399 </xsl:variable>
400 <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)">
401 </xsl:variable>
402 <xsl:element name="span" namespace="{$KorAP_namespace}">
403 <xsl:attribute name="id" select="'s' || $my_index"/>
404 <xsl:attribute name="from" select="$start"/>
405 <xsl:attribute name="to" select="$end"/>
406 <xsl:attribute name="l" select="f:compute_nesting(.)"/>
407 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
408 <xsl:attribute name="type" select="'lex'"/>
409 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
410 <xsl:attribute name="name" select="'lex'"/>
411 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
412 <xsl:comment select="$my_morph-seg//tei:fs/tei:f[@name eq 'orth']/tei:string"/>
413
414
415 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
416 <xsl:attribute name="name" select="'lemma'"/>
417 <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'base']/tei:string"/>
418 </xsl:element>
419 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
420 <xsl:attribute name="name" select="'pos'"/>
421 <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'ctag']/tei:symbol/@value"/>
422 </xsl:element>
423 <xsl:if test="string-length($chosen-msd)">
424 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
425 <xsl:attribute name="name" select="'msd'"/>
426 <xsl:value-of select="$chosen-msd"/>
427 </xsl:element>
428 </xsl:if>
429 <xsl:if test="$my_morph-seg//tei:fs/tei:f[@name eq 'nps']">
430 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
431 <xsl:attribute name="name" select="'join'"/>
432 <xsl:value-of select="'left'"/>
433 </xsl:element>
434 </xsl:if>
435 </xsl:element>
436 </xsl:element>
437 </xsl:element>
438 </xsl:element>
439 <xsl:apply-templates mode="morpho">
440 <xsl:with-param name="ini" select="$start" as="xs:integer"/>
441 <xsl:with-param name="fin" select="$end" as="xs:integer"/>
442 <xsl:with-param name="index" select="$my_index"/>
443 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/>
444 </xsl:apply-templates>
445 </xsl:template>
bansp5f841732022-03-16 06:27:31 +0100446 <!-- ************************** TEXT header ******************* -->
447
448 <xsl:template name="create_text_header">
449 <xsl:param name="text.xml" as="document-node()"/>
450 <xsl:param name="target" as="xs:string"/>
451
452 <!-- create the local header.xml file -->
453 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
454 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
455
456 <idsHeader type="document" pattern="text" status="new" version="1.1" TEIform="teiHeader">
bansp9103aab2022-03-19 05:10:21 +0100457 <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:*" mode="text"/>
bansp5f841732022-03-16 06:27:31 +0100458 </idsHeader>
459 </xsl:result-document>
460 </xsl:template>
461
462 <xsl:template match="tei:fileDesc" mode="text">
bansp9103aab2022-03-19 05:10:21 +0100463 <xsl:element name="{local-name()}">
bansp5f841732022-03-16 06:27:31 +0100464 <xsl:apply-templates mode="text"/>
bansp9103aab2022-03-19 05:10:21 +0100465 </xsl:element>
bansp5f841732022-03-16 06:27:31 +0100466 </xsl:template>
467
468 <xsl:template match="tei:title" mode="text">
469 <t.title>
470 <xsl:apply-templates/>
471 </t.title>
472 </xsl:template>
473
474 <xsl:template match="tei:titleStmt" mode="text">
475 <titleStmt>
476 <textSigle>
banspba37fb92022-03-22 03:34:48 +0100477 <xsl:value-of select="$corpusID || '/' || $docID || '.' || $textID"/>
bansp5f841732022-03-16 06:27:31 +0100478 </textSigle>
479 <xsl:apply-templates mode="text"/>
480 </titleStmt>
481 </xsl:template>
482
bansp9103aab2022-03-19 05:10:21 +0100483 <xsl:template match="tei:publicationStmt" mode="text">
484 <xsl:element name="{local-name()}">
485 <xsl:apply-templates mode="text"/>
486 </xsl:element>
487 </xsl:template>
488
489 <xsl:template match="tei:availability" mode="text">
490 <xsl:element name="{local-name()}">
491 <xsl:apply-templates mode="text" select="@* | *"/>
492 </xsl:element>
493 </xsl:template>
494
495 <xsl:template match="tei:profileDesc" mode="text">
496 <xsl:element name="{local-name()}">
497 <xsl:apply-templates mode="text"/>
498 </xsl:element>
499 </xsl:template>
bansp5f841732022-03-16 06:27:31 +0100500
bansp9103aab2022-03-19 05:10:21 +0100501 <xsl:template match="tei:textClass" mode="text">
502 <xsl:element name="{local-name()}">
503 <xsl:apply-templates mode="text" select="@* | *"/>
504 </xsl:element>
505 </xsl:template>
506
507 <xsl:template match="tei:catRef" mode="text corpus">
508 <xsl:element name="{local-name()}">
509 <xsl:apply-templates mode="text" select="@* | *"/>
510 </xsl:element>
511 </xsl:template>
512
513 <xsl:template match="@status | @scheme | @target | @type | @xml:id[ancestor::tei:classDecl] | @xml:lang" mode="text corpus">
514 <xsl:copy-of select="."/>
515 </xsl:template>
516
517 <xsl:template match="tei:p" mode="text corpus">
518 <xsl:element name="{local-name()}">
519 <xsl:apply-templates mode="header-text"/>
520 </xsl:element>
521 </xsl:template>
522
523
524 <!-- OPTIMIZATION has to take modes into account -->
bansp5e2d1c02022-03-10 04:51:40 +0100525 <!-- ************************** CORPUS header ******************* -->
526 <xsl:template name="create_corpus_header">
527 <xsl:param name="text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100528 <xsl:param name="target" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100529
530 <!-- create the corpus-level header.xml file -->
bansp5f841732022-03-16 06:27:31 +0100531 <xsl:result-document encoding="UTF-8" method="xml" indent="yes" href="{$target}">
bansp5e2d1c02022-03-10 04:51:40 +0100532
533 <!--doctype-public="{$publicDoctypeI5}"
534 doctype-system="{$systemDoctypeI5}">
535 these are, sadly, useless
536 -->
537
538 <idsHeader type="corpus" pattern="text" status="new" version="1.1" TEIform="teiHeader">
bansp9103aab2022-03-19 05:10:21 +0100539 <xsl:apply-templates select="$text.xml/tei:teiCorpus/tei:teiHeader/tei:*" mode="corpus"/>
bansp5e2d1c02022-03-10 04:51:40 +0100540 </idsHeader>
541 </xsl:result-document>
542 </xsl:template>
543
544 <xsl:template match="tei:fileDesc" mode="corpus">
bansp9103aab2022-03-19 05:10:21 +0100545 <xsl:element name="{local-name()}">
bansp5e2d1c02022-03-10 04:51:40 +0100546 <xsl:apply-templates mode="corpus"/>
bansp9103aab2022-03-19 05:10:21 +0100547 </xsl:element>
bansp5e2d1c02022-03-10 04:51:40 +0100548 </xsl:template>
bansp9103aab2022-03-19 05:10:21 +0100549
bansp5e2d1c02022-03-10 04:51:40 +0100550
551 <xsl:template match="tei:title" mode="corpus">
552 <c.title>
bansp9103aab2022-03-19 05:10:21 +0100553 <xsl:apply-templates mode="corpus" select="@*"/>
554 <xsl:apply-templates mode="header-text"/>
bansp5e2d1c02022-03-10 04:51:40 +0100555 </c.title>
556 </xsl:template>
557
558 <xsl:template match="tei:titleStmt" mode="corpus">
559 <titleStmt>
560 <korpusSigle>
561 <xsl:value-of select="$corpusID"/>
562 </korpusSigle>
563 <xsl:apply-templates mode="corpus"/>
564 </titleStmt>
565 </xsl:template>
566
bansp9103aab2022-03-19 05:10:21 +0100567 <xsl:template match="tei:publicationStmt" mode="corpus">
568 <xsl:element name="{local-name()}">
569 <xsl:apply-templates mode="corpus"/>
570 </xsl:element>
571 </xsl:template>
572
573 <xsl:template match="tei:availability" mode="corpus">
574 <xsl:element name="{local-name()}">
575 <xsl:apply-templates mode="corpus" select="@* | *"/>
576 </xsl:element>
577 </xsl:template>
578
579 <xsl:template match="tei:encodingDesc" mode="corpus">
580 <xsl:element name="{local-name()}">
581 <xsl:apply-templates mode="corpus"/>
582 </xsl:element>
583 </xsl:template>
584
585 <xsl:template match="tei:classDecl | tei:taxonomy | tei:category | tei:taxonomy/tei:bibl" mode="corpus">
586 <xsl:element name="{local-name()}">
587 <xsl:apply-templates mode="corpus" select="@* | *"/>
588 </xsl:element>
589 </xsl:template>
590
591 <xsl:template match="tei:bibl/tei:title | tei:edition | tei:desc" mode="corpus">
592 <xsl:element name="{local-name()}">
593 <xsl:apply-templates mode="corpus" select="@*"/>
594 <xsl:apply-templates mode="header-text"/>
595 </xsl:element>
596 </xsl:template>
597<!--
598 <xsl:template match="tei:textClass" mode="corpus">
599 <xsl:element name="{local-name()}">
600 <xsl:apply-templates mode="corpus" select="@* | *"/>
601 </xsl:element>
602 </xsl:template>
603
604 <xsl:template match="tei:catRef" mode="corpus">
605 <xsl:element name="{local-name()}">
606 <xsl:apply-templates mode="corpus" select="@* | *"/>
607 </xsl:element>
608 </xsl:template>
609-->
bansp5e2d1c02022-03-10 04:51:40 +0100610
611
612
613 <!-- this template can be called by the XSPEC test; TODO: find a way to call the main() template directly -->
614 <!-- I have not fully handled the param transmission, which would have to be kludged in just for the sake of XSPec,
615 because I'm disabling this for now, due to XSpec design issues; relevant links, a.o.:
616
617 https://stackoverflow.com/questions/64933277/what-is-the-cause-of-error-cannot-execute-xslresult-document-while-evaluating
618 https://www.balisage.net/Proceedings/vol25/html/Galtman01/BalisageVol25-Galtman01.html
619
620 In short: the internal design of XSpec forces kludges when one wants to use xsl:result-document in their stylesheets. But I don't
621 want to be strangled by kludges at the beginning of work, I've already lost quite a bit of time on this investigation,
622 I will therefore "just code" and then can think of externalizing bits of templates if we want to play with tests. For now,
623 I don't want to have to handle context items is a special way inside variables, etc., because I'm not sure it's worth it.
624
625 -->
626 <!--<xsl:template name="test_full">
627 <xsl:param name="corpusID"/>
628 <xsl:param name="docID"/>
629 <xsl:param name="textID"/>
630 <xsl:call-template name="xsl:initial-template"/>
631 </xsl:template>-->
632
Akron9a8ee3e2022-01-31 13:51:49 +0100633</xsl:stylesheet>