blob: 64b65e18383f1b31cd42b52024afa3dd4f2abebc [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"
Piotr Banskif8af3a92022-05-23 03:20:10 +02005 xmlns:fn="http://www.w3.org/2005/xpath-functions"
Piotr Banski6a4a2522022-05-24 01:16:47 +02006 xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs f fn map nkjp tei"
bansp5e2d1c02022-03-10 04:51:40 +01007 version="3.0" expand-text="yes">
Akron9a8ee3e2022-01-31 13:51:49 +01008
banspe726b4a2022-03-28 05:47:45 +02009
10<!-- PARAMETERS -->
bansp5e2d1c02022-03-10 04:51:40 +010011
bansp8f6700b2022-03-27 05:27:09 +020012 <xsl:param name="sourceDir" select="'test/resources/nkjp2korap_sample2'" as="xs:string"/>
banspd1bf1db2022-04-04 02:16:24 +020013 <!-- the directory containing NKJP files, in the form of a collection of text-level dirs
14 (that is how we know both the $corpusID and the $docID) -->
Akron9a8ee3e2022-01-31 13:51:49 +010015
bansp8f6700b2022-03-27 05:27:09 +020016 <xsl:param name="targetDir" select="'test/output'" as="xs:string"/>
banspd1bf1db2022-04-04 02:16:24 +020017 <!-- where the corpus/document/text/annotations hierarchy is going to be created -->
banspf2b24e62022-03-28 18:12:08 +020018
19 <xsl:param name="skip_docID" as="xs:string">
Piotr Banskic5950ce2022-05-27 15:07:08 +020020 <!--<xsl:value-of select="''"/>-->
21 <xsl:value-of select="'HellerPodgladanie,IsakowiczZaleskiMoje,KolakowskiOco,MysliwskiKamien,WilkWilczy,ZycieWarszawy_Zycie'"/>
banspb5992532022-03-29 15:55:44 +020022 </xsl:param>
23 <!-- comma-separated list of document IDs to be skipped from processing
banspf2b24e62022-03-28 18:12:08 +020024 example: HellerPodgladanie,KOT
banspd1bf1db2022-04-04 02:16:24 +020025 no functionality beyond string identity is supported
26 (this is just for testing) -->
banspb5992532022-03-29 15:55:44 +020027
Piotr Banski1ae16bd2022-05-25 15:59:40 +020028 <xsl:param name="SHOW_ORTH_IN_STRUCT" as="xs:boolean" select="true()"/>
Piotr Banski09096ee2022-05-25 13:41:03 +020029 <!-- for debugging structure.xml production -->
30
bansp8f6700b2022-03-27 05:27:09 +020031
bansp9dc10002022-05-17 22:33:34 +020032<!-- VARIABLES (= constants...) -->
banspe726b4a2022-03-28 05:47:45 +020033
34 <xsl:variable name="corpusID" as="xs:string" select="'NKJP'" static="yes"/>
35 <xsl:variable name="docID" as="xs:string" select="'NKJP'" static="yes"/>
bansp8f6700b2022-03-27 05:27:09 +020036
37 <xsl:variable name="targetCorpusDir_slashed" select="$targetDir || '/' || $corpusID || '/'" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +010038
banspd1bf1db2022-04-04 02:16:24 +020039 <xsl:variable name="systemDoctypeI5" as="xs:string"
40 select="'http://corpora.ids-mannheim.de/I5/DTD/i5.dtd'" static="true"/>
bansp5e2d1c02022-03-10 04:51:40 +010041
banspd1bf1db2022-04-04 02:16:24 +020042 <xsl:variable name="publicDoctypeI5" as="xs:string" static="true"
43 select="'-//IDS//DTD I5 1.0//EN'"/>
bansp5e2d1c02022-03-10 04:51:40 +010044
banspd1bf1db2022-04-04 02:16:24 +020045 <xsl:variable name="KorAP_namespace" static="true" as="xs:string"
46 select="'http://ids-mannheim.de/ns/KorAP'"/>
bansp5e2d1c02022-03-10 04:51:40 +010047
bansp5f841732022-03-16 06:27:31 +010048 <xsl:variable name="KorAP-XML_version" select="'KorAP-0.4'" as="xs:string" static="true"/>
49 <!-- this is only a bit funny -->
50
banspe726b4a2022-03-28 05:47:45 +020051 <xsl:variable name="collection_params" as="xs:string" static="yes"
52 select="'recurse=yes;validation=strip;select=text.xml;content-type=application/xml;on-error=warning;xinclude=yes'"
53 />
54 <!-- see https://www.saxonica.com/documentation11/index.html#!sourcedocs/collections/collection-directories -->
55
56 <xsl:variable name="collection_of_text" select="collection($sourceDir || '?' || $collection_params)" as="document-node()+"/>
banspd1bf1db2022-04-04 02:16:24 +020057
banspe726b4a2022-03-28 05:47:45 +020058<!-- MODES -->
bansp5e2d1c02022-03-10 04:51:40 +010059
60 <xsl:mode name="corpus" on-no-match="deep-skip"/>
61 <xsl:mode name="text" on-no-match="deep-skip"/>
bansp9103aab2022-03-19 05:10:21 +010062 <xsl:mode name="header-text" on-no-match="text-only-copy"/>
Piotr Banski6a4a2522022-05-24 01:16:47 +020063 <xsl:mode use-accumulators="#all"/>
Piotr Banski09096ee2022-05-25 13:41:03 +020064
65 <xsl:accumulator name="element-index" as="xs:integer" initial-value="0">
66 <xsl:accumulator-rule match="tei:*[ancestor-or-self::tei:text]" select="$value + 1" phase="start"/>
67 </xsl:accumulator>
Piotr Banskifdc858a2022-05-25 02:40:32 +020068
69 <xsl:accumulator name="elem-offset-seq" as="map(xs:string, item()+)+" initial-value="(map{'null':(0,0)})">
70
71 <xsl:accumulator-rule match="tei:body/tei:p" phase="start">
72 <xsl:variable name="preceding_index" as="xs:integer">
73 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
74 <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/>
Piotr Banski6a4a2522022-05-24 01:16:47 +020075 </xsl:variable>
76
Piotr Banskifdc858a2022-05-25 02:40:32 +020077 <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + 1"/>
78 <!-- for paragraphs, it's in either being initial or not -->
Piotr Banski09096ee2022-05-25 13:41:03 +020079
Piotr Banskifdc858a2022-05-25 02:40:32 +020080 <xsl:sequence select="
81 $value,
82 map {
83 string(@xml:id): ($preceding_index,$our_base)
84 }"/>
85 </xsl:accumulator-rule>
86
87 <xsl:accumulator-rule match="tei:s" phase="start">
88 <xsl:variable name="preceding_index" as="xs:integer">
89 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
90 <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/>
Piotr Banskifdc858a2022-05-25 02:40:32 +020091 </xsl:variable>
Piotr Banski92791a22022-05-26 01:41:10 +020092 <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + xs:integer(f:is_preceded_by_ws(.,true()))"/>
Piotr Banski09096ee2022-05-25 13:41:03 +020093
Piotr Banskifdc858a2022-05-25 02:40:32 +020094 <xsl:sequence select="
95 $value,
96 map {
97 string(@xml:id): ($preceding_index,$our_base)
98 }"/>
99 </xsl:accumulator-rule>
100
101 <xsl:accumulator-rule match="tei:w[parent::tei:seg[count(@nkjp:rejected) eq 0]]" phase="end">
102 <xsl:variable name="preceding_index" as="xs:integer">
103 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
104 <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/>
Piotr Banskifdc858a2022-05-25 02:40:32 +0200105 </xsl:variable>
106 <xsl:variable name="our_base" as="xs:integer" select="$preceding_index + xs:integer(f:is_preceded_by_ws(parent::tei:seg,true()))"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200107
Piotr Banski6a4a2522022-05-24 01:16:47 +0200108 <xsl:sequence select="
109 $value,
110 map {
Piotr Banski69f3c5f2022-05-24 10:52:09 +0200111 string(parent::tei:seg/@xml:id): ($our_base,$our_base + string-length())
Piotr Banski6a4a2522022-05-24 01:16:47 +0200112 }"/>
113 </xsl:accumulator-rule>
Piotr Banskifdc858a2022-05-25 02:40:32 +0200114
115 <xsl:accumulator-rule match="tei:s" phase="end">
116 <xsl:variable name="preceding_index" as="xs:integer">
117 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
118 <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200119
Piotr Banskifdc858a2022-05-25 02:40:32 +0200120 </xsl:variable>
121 <xsl:variable name="our_base" as="xs:integer">
122 <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/>
123 <xsl:sequence select="$incomplete[2]"/>
124 </xsl:variable>
Piotr Banski09096ee2022-05-25 13:41:03 +0200125
Piotr Banskifdc858a2022-05-25 02:40:32 +0200126 <xsl:sequence select="
127 $value,
128 map {
129 string(@xml:id): ($our_base,$preceding_index)
130 }"/>
131 </xsl:accumulator-rule>
132
133 <xsl:accumulator-rule match="tei:body/tei:p" phase="end">
134 <xsl:variable name="preceding_index" as="xs:integer">
135 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
136 <xsl:sequence select="map:get($the_tail,map:keys($the_tail)[1])[2]"/>
137
Piotr Banskifdc858a2022-05-25 02:40:32 +0200138 </xsl:variable>
139 <xsl:variable name="our_base" as="xs:integer">
140 <xsl:variable name="incomplete" select="map:find($value,string(@xml:id))(1)" as="xs:integer+"/>
141 <xsl:sequence select="$incomplete[2]"/>
142 </xsl:variable>
Piotr Banski09096ee2022-05-25 13:41:03 +0200143
Piotr Banskifdc858a2022-05-25 02:40:32 +0200144 <xsl:sequence select="
145 $value,
146 map {
147 string(@xml:id): ($our_base,$preceding_index)
148 }"/>
149 </xsl:accumulator-rule>
150
151 <xsl:accumulator-rule match="tei:body" phase="end">
152 <xsl:variable name="preceding_index" as="xs:integer">
153 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
154 <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/>
155 </xsl:variable>
156
157 <xsl:sequence select="
158 $value,
159 map {
160 string(@xml:id): (0, $preceding_index)
161 }"/>
162 </xsl:accumulator-rule>
163
164 <xsl:accumulator-rule match="tei:text" phase="end">
165 <xsl:variable name="preceding_index" as="xs:integer">
166 <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
167 <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/>
168 </xsl:variable>
169
170 <xsl:sequence select="
171 $value,
172 map {
173 string(@xml:id): (0, $preceding_index)
174 }"/>
175 </xsl:accumulator-rule>
Piotr Banski6a4a2522022-05-24 01:16:47 +0200176 </xsl:accumulator>
bansp5e2d1c02022-03-10 04:51:40 +0100177
banspe726b4a2022-03-28 05:47:45 +0200178 <!-- FUNCTIONS -->
179
bansp5f841732022-03-16 06:27:31 +0100180 <xsl:function name="f:compute_nesting" as="xs:integer">
banspd1bf1db2022-04-04 02:16:24 +0200181 <xsl:param name="node" as="element()"/>
bansp5f841732022-03-16 06:27:31 +0100182 <xsl:variable name="rel_depth"
183 select="count($node/ancestor-or-self::*[local-name(.) ne 'TEI'][local-name(.) ne 'teiCorpus'])"
184 as="xs:integer"/>
bansp5f841732022-03-16 06:27:31 +0100185 <xsl:sequence select="$rel_depth"/>
186 </xsl:function>
187
Piotr Banski92791a22022-05-26 01:41:10 +0200188 <xsl:function name="f:is_preceded_by_ws" as="xs:boolean">
bansp9dc10002022-05-17 22:33:34 +0200189 <xsl:param name="node" as="element()"/>
Piotr Banskifdc858a2022-05-25 02:40:32 +0200190 <xsl:param name="suppress_initial" as="xs:boolean"/>
Piotr Banski4f4c2d22022-05-19 01:44:32 +0200191
Piotr Banski92791a22022-05-26 01:41:10 +0200192 <xsl:choose>
193 <xsl:when test="local-name($node) eq 'seg'">
194 <xsl:choose>
195 <xsl:when test="$node/@nkjp:nps">
196 <xsl:sequence select="fn:false()"/>
197 </xsl:when>
198 <xsl:when
199 test="$node/ancestor::tei:s[count(preceding-sibling::tei:s) eq 0] and $node/ancestor::tei:p[count(preceding-sibling::tei:p) eq 0] and not($node/preceding::tei:seg[count(@nkjp:rejected) eq 0])">
200 <xsl:sequence select="fn:false()"/>
201 <!-- the otherwise very costly check for preceding segs fires only if the first two are true, so it will have minimal search space -->
202 </xsl:when>
203 <xsl:when
204 test="$suppress_initial and $node/ancestor::tei:s/descendant::tei:seg[count(@nkjp:rejected) eq 0][1]/@xml:id eq $node/@xml:id">
205 <!-- I forget how node identity works now, so let me just compare the IDs -->
206 <xsl:sequence select="fn:false()"/>
207 </xsl:when>
208 <xsl:otherwise>
209 <xsl:sequence select="fn:true()"/>
210 </xsl:otherwise>
211 </xsl:choose>
212 </xsl:when>
213 <xsl:when test="local-name($node) eq 's'">
214 <xsl:choose>
215 <xsl:when test="exists($node/preceding-sibling::tei:s)">
216 <xsl:sequence select="fn:true()"/>
217 </xsl:when>
218 <xsl:otherwise>
219 <xsl:sequence
220 select="not($suppress_initial) and exists($node/ancestor::tei:p[1]/preceding-sibling::tei:p)"
221 />
222 </xsl:otherwise>
223 </xsl:choose>
224
225 </xsl:when>
226 <xsl:when test="local-name($node) eq 'p'">
227 <xsl:sequence select="exists($node/preceding-sibling::tei:p)"/>
228 </xsl:when>
229 <xsl:otherwise>
230 <xsl:message terminate="yes"
231 select="'Wrong argument passed to f:is_preceded_by_ws(): ' || local-name($node) || ' Only p, s, seg are allowed.'"
232 />
233 </xsl:otherwise>
234 </xsl:choose>
235 </xsl:function>
banspd1bf1db2022-04-04 02:16:24 +0200236
banspb5992532022-03-29 15:55:44 +0200237<!-- UTILITY TEMPLATES -->
238
bansp9103aab2022-03-19 05:10:21 +0100239 <xsl:template match="@default" mode="#all"/>
bansp97ba7ce2022-03-26 05:14:06 +0100240 <!-- this is to delete some auto-inserted attribute throughout -->
bansp9103aab2022-03-19 05:10:21 +0100241
Piotr Banski6a4a2522022-05-24 01:16:47 +0200242 <xsl:template match="tei:w" mode="#all"/>
banspe726b4a2022-03-28 05:47:45 +0200243<!-- NKJP-SGJP has apparently resigned from standoff representations by adding <w> everywhere;
Piotr Banskifdc858a2022-05-25 02:40:32 +0200244 we reach for them, but from the level of <seg>, so we don't need to process <w> separately -->
bansp8f6700b2022-03-27 05:27:09 +0200245
Piotr Banski09096ee2022-05-25 13:41:03 +0200246 <!-- fall-thru, skipping the potential <paren> element and filtering out the bad guys -->
Piotr Banski6a4a2522022-05-24 01:16:47 +0200247 <xsl:template match="tei:choice" mode="struct">
Piotr Banski09096ee2022-05-25 13:41:03 +0200248 <xsl:apply-templates select="descendant::tei:seg[count(@nkjp:rejected) eq 0]" mode="struct"/>
Piotr Banski6a4a2522022-05-24 01:16:47 +0200249 </xsl:template>
Piotr Banskia51907c2022-05-25 15:09:41 +0200250 <xsl:template match="tei:choice" mode="morpho">
251 <xsl:apply-templates select="descendant::tei:seg[count(@nkjp:rejected) eq 0]" mode="morpho"/>
252 </xsl:template>
banspb5992532022-03-29 15:55:44 +0200253
254 <!-- MAIN PROCESSING -->
255
bansp5e2d1c02022-03-10 04:51:40 +0100256 <xsl:template name="xsl:initial-template">
banspf2b24e62022-03-28 18:12:08 +0200257 <xsl:variable name="IDs_to_skip" select="tokenize($skip_docID,',')" as="xs:string*"/>
banspd1bf1db2022-04-04 02:16:24 +0200258
banspe726b4a2022-03-28 05:47:45 +0200259 <!-- we only want to call the template below once, and we process a random NKJP corpus file for that purpose,
bansp8f6700b2022-03-27 05:27:09 +0200260 because all we need is the main corpus header, and we can (should) get to that from any NKJP corpus document -->
261 <xsl:call-template name="create_corpus_header">
banspe726b4a2022-03-28 05:47:45 +0200262 <xsl:with-param name="text.xml" select="$collection_of_text[1]" as="document-node()"/>
bansp8f6700b2022-03-27 05:27:09 +0200263 <xsl:with-param name="target" select="$targetCorpusDir_slashed || 'header.xml'" as="xs:string"/>
264 </xsl:call-template>
265
banspe726b4a2022-03-28 05:47:45 +0200266 <xsl:for-each select="$collection_of_text">
267 <xsl:variable name="my_dir" as="xs:string" select="replace(base-uri(),'/text\.xml','')"/>
268 <xsl:variable name="my_textID" as="xs:string" select="tokenize($my_dir,'/')[last()]"/>
269 <xsl:variable name="ann_morphosyntax.uri" select="$my_dir || '/ann_morphosyntax.xml'" as="xs:string"/>
270 <xsl:variable name="ann_segmentation.uri" select="$my_dir || '/ann_segmentation.xml'" as="xs:string"/>
Piotr Banskic5950ce2022-05-27 15:07:08 +0200271 <xsl:variable name="ann_named.uri" select="$my_dir || '/ann_named.xml'" as="xs:string"/>
272 <xsl:variable name="ann_groups.uri" select="$my_dir || '/ann_groups.xml'" as="xs:string"/>
273 <xsl:variable name="ann_words.uri" select="$my_dir || '/ann_words.xml'" as="xs:string"/>
banspe726b4a2022-03-28 05:47:45 +0200274
banspf2b24e62022-03-28 18:12:08 +0200275 <xsl:choose>
276 <xsl:when test="$my_textID = $IDs_to_skip"/>
bansp9dc10002022-05-17 22:33:34 +0200277 <!-- this is a utility step, for when we want to ignore some texts for any reason (debugging, selective update) -->
banspf2b24e62022-03-28 18:12:08 +0200278 <xsl:otherwise>
banspd1bf1db2022-04-04 02:16:24 +0200279
bansp9dc10002022-05-17 22:33:34 +0200280 <xsl:call-template name="process_single_sample">
banspf2b24e62022-03-28 18:12:08 +0200281 <xsl:with-param name="text.xml" as="document-node()" select="."/>
282 <xsl:with-param name="ann_morphosyntax.xml" as="document-node()"
283 select="doc($ann_morphosyntax.uri)"/>
284 <xsl:with-param name="ann_segmentation.xml" as="document-node()"
285 select="doc($ann_segmentation.uri)"/>
286 <xsl:with-param name="my_textID" select="$my_textID" as="xs:string"/>
Piotr Banskic5950ce2022-05-27 15:07:08 +0200287 <!-- the following parameters may happen to be null -->
288 <xsl:with-param name="ann_named.xml" as="document-node()*"
289 select="if(fn:doc-available($ann_named.uri)) then doc($ann_named.uri) else ()"/>
290 <xsl:with-param name="ann_groups.xml" as="document-node()*"
291 select="if(fn:doc-available($ann_groups.uri)) then doc($ann_groups.uri) else ()"/>
292 <xsl:with-param name="ann_words.xml" as="document-node()*"
293 select="if(fn:doc-available($ann_words.uri)) then doc($ann_words.uri) else ()"/>
294
bansp9dc10002022-05-17 22:33:34 +0200295 </xsl:call-template>
banspf2b24e62022-03-28 18:12:08 +0200296 </xsl:otherwise>
297 </xsl:choose>
banspe726b4a2022-03-28 05:47:45 +0200298 </xsl:for-each>
bansp8f6700b2022-03-27 05:27:09 +0200299 </xsl:template>
300
301 <xsl:template name="process_single_sample">
banspe726b4a2022-03-28 05:47:45 +0200302 <xsl:param name="text.xml" as="document-node()"/>
303 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
304 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
banspd1bf1db2022-04-04 02:16:24 +0200305 <xsl:param name="my_textID" as="xs:string" select="'0-BAD_textID'"/>
bansp9dc10002022-05-17 22:33:34 +0200306 <!-- empty textID should never happen, but if it does, it will be signalled at the top of the output -->
Piotr Banskic5950ce2022-05-27 15:07:08 +0200307 <xsl:param name="ann_named.xml" as="document-node()*"/>
308 <xsl:param name="ann_groups.xml" as="document-node()*"/>
309 <xsl:param name="ann_words.xml" as="document-node()*"/>
banspe726b4a2022-03-28 05:47:45 +0200310
311 <xsl:variable name="targetBaseDir" as="xs:string" select="$targetCorpusDir_slashed || $docID || '/' || $my_textID"/>
312
313 <xsl:variable name="compoundID" as="xs:string"
314 select="$corpusID || '_' || $docID || '.' || $my_textID"/>
315 <!-- this is what occurs in the text and data layers as @docid -->
316
bansp5e2d1c02022-03-10 04:51:40 +0100317 <xsl:call-template name="create_data">
bansp9dc10002022-05-17 22:33:34 +0200318 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200319 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
320 <xsl:with-param name="target" select="$targetBaseDir || '/data.xml'" as="xs:string"/>
bansp5f841732022-03-16 06:27:31 +0100321 </xsl:call-template>
322
Piotr Banski4f4c2d22022-05-19 01:44:32 +0200323 <xsl:call-template name="create_struct">
banspe726b4a2022-03-28 05:47:45 +0200324 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
bansp5f841732022-03-16 06:27:31 +0100325 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
326 as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200327 <xsl:with-param name="target" select="$targetBaseDir || '/struct/structure.xml'" as="xs:string"
bansp5f841732022-03-16 06:27:31 +0100328 />
329 </xsl:call-template>
Piotr Banski92791a22022-05-26 01:41:10 +0200330
Piotr Banskia51907c2022-05-25 15:09:41 +0200331 <xsl:call-template name="create_morpho">
banspe726b4a2022-03-28 05:47:45 +0200332 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
bansp3e5b20c2022-03-18 20:22:31 +0100333 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
334 as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100335 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml"
336 as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200337 <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/morpho.xml'" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100338 </xsl:call-template>
Piotr Banskia51907c2022-05-25 15:09:41 +0200339
Piotr Banski09096ee2022-05-25 13:41:03 +0200340 <xsl:call-template name="create_text_header">
bansp5e2d1c02022-03-10 04:51:40 +0100341 <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200342 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
343 <xsl:with-param name="target" select="$targetBaseDir || '/header.xml'" as="xs:string"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200344 </xsl:call-template>
Piotr Banski6a4a2522022-05-24 01:16:47 +0200345
Piotr Banskic5950ce2022-05-27 15:07:08 +0200346 <xsl:if test="$ann_named.xml">
347 <xsl:call-template name="create_named">
348 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
349 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
350 as="document-node()"/>
351 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml"
352 as="document-node()"/>
353 <xsl:with-param name="ann_named.xml" select="$ann_named.xml"
354 as="document-node()"/>
355 <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/named.xml'" as="xs:string"/>
356 </xsl:call-template>
357 </xsl:if>
358
359 <xsl:if test="$ann_words.xml and $ann_groups.xml">
360 <xsl:call-template name="create_groups">
361 <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
362 <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
363 as="document-node()"/>
364 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml"
365 as="document-node()"/>
366 <xsl:with-param name="ann_words.xml" select="$ann_words.xml"
367 as="document-node()"/>
368 <xsl:with-param name="ann_groups.xml" select="$ann_groups.xml"
369 as="document-node()"/>
370 <xsl:with-param name="target" select="$targetBaseDir || '/nkjp/groups.xml'" as="xs:string"/>
371 </xsl:call-template>
372 </xsl:if>
373
bansp5e2d1c02022-03-10 04:51:40 +0100374 </xsl:template>
375
376 <!-- ************************** data.xml ******************* -->
377
378 <xsl:template name="create_data">
bansp9dc10002022-05-17 22:33:34 +0200379 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200380 <xsl:param name="compoundID" as="xs:string"/>
bansp5f841732022-03-16 06:27:31 +0100381 <xsl:param name="target" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100382 <!-- create the data.xml file -->
383 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
bansp5f841732022-03-16 06:27:31 +0100384 xpath-default-namespace="{$KorAP_namespace}" href="{$target}">
bansp5e2d1c02022-03-10 04:51:40 +0100385
Akron9a8ee3e2022-01-31 13:51:49 +0100386 <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 +0100387 <xsl:element name="raw_text" namespace="{$KorAP_namespace}">
bansp5f841732022-03-16 06:27:31 +0100388 <xsl:attribute name="docid" select="$compoundID"/>
bansp5e2d1c02022-03-10 04:51:40 +0100389 <xsl:element name="metadata" namespace="{$KorAP_namespace}">
390 <xsl:attribute name="file" select="'metadata.xml'"/>
391 </xsl:element>
392
393 <xsl:element name="text" namespace="{$KorAP_namespace}">
bansp9dc10002022-05-17 22:33:34 +0200394 <xsl:variable name="content" as="xs:string+">
Piotr Banski4f4c2d22022-05-19 01:44:32 +0200395 <xsl:for-each select="$ann_segmentation.xml/tei:teiCorpus/tei:TEI/tei:text/tei:body/tei:p/tei:s//tei:seg[count(@nkjp:rejected) eq 0]">
bansp9dc10002022-05-17 22:33:34 +0200396 <xsl:sequence select="
Piotr Banskifdc858a2022-05-25 02:40:32 +0200397 if (f:is_preceded_by_ws(.,false())) then
bansp9dc10002022-05-17 22:33:34 +0200398 ' '
399 else
400 '', ./tei:w"/>
401 </xsl:for-each>
402 </xsl:variable>
403 <xsl:value-of select="string-join($content)"/>
bansp5e2d1c02022-03-10 04:51:40 +0100404 </xsl:element>
Akron9a8ee3e2022-01-31 13:51:49 +0100405 </xsl:element>
banspf79443e2022-02-25 14:25:33 +0100406 </xsl:result-document>
Akron9a8ee3e2022-01-31 13:51:49 +0100407 </xsl:template>
408
bansp5f841732022-03-16 06:27:31 +0100409 <!-- ************************** struct ******************* -->
410
411 <xsl:template name="create_struct">
banspe726b4a2022-03-28 05:47:45 +0200412 <xsl:param name="compoundID" as="xs:string"/>
bansp5f841732022-03-16 06:27:31 +0100413 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
414 <xsl:param name="target" as="xs:string"/>
Piotr Banski4f4c2d22022-05-19 01:44:32 +0200415
bansp5f841732022-03-16 06:27:31 +0100416 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
417 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
418 <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>
419 <xsl:element name="layer" namespace="{$KorAP_namespace}">
420 <xsl:attribute name="docid" select="$compoundID"/>
421 <xsl:attribute name="version" select="$KorAP-XML_version"/>
422
423 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
Piotr Banski09096ee2022-05-25 13:41:03 +0200424 <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/>
bansp5f841732022-03-16 06:27:31 +0100425 </xsl:element>
426 </xsl:element>
427 </xsl:result-document>
428 </xsl:template>
429
430 <xsl:template match="tei:*" mode="struct">
Piotr Banski09096ee2022-05-25 13:41:03 +0200431 <xsl:variable name="offsets" as="xs:integer+">
432 <xsl:variable name="akku"
433 select="map:merge(tail(fn:accumulator-after('elem-offset-seq')), map {'duplicates': 'use-last'})"
434 as="map(xs:string,xs:integer+)"/> <!--test later if the merger is really needed here, given how accus work-->
435 <xsl:sequence select="map:get($akku, string(@xml:id))"/>
436 </xsl:variable>
Piotr Banski6a4a2522022-05-24 01:16:47 +0200437
bansp5f841732022-03-16 06:27:31 +0100438 <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200439 <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>
bansp3e5b20c2022-03-18 20:22:31 +0100440
bansp5f841732022-03-16 06:27:31 +0100441 <xsl:element name="span" namespace="{$KorAP_namespace}">
442 <xsl:attribute name="id" select="'s' || $my_index"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200443 <xsl:attribute name="from" select="$offsets[1]"/>
444 <xsl:attribute name="to" select="$offsets[2]"/>
bansp5f841732022-03-16 06:27:31 +0100445 <xsl:attribute name="l" select="f:compute_nesting(.)"/>
Piotr Banski09096ee2022-05-25 13:41:03 +0200446 <xsl:if test="local-name() eq 'seg' and $SHOW_ORTH_IN_STRUCT">
447 <xsl:comment><xsl:value-of select="fn:normalize-space(.)"/></xsl:comment>
448 </xsl:if>
bansp5f841732022-03-16 06:27:31 +0100449 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
Piotr Banskifdc858a2022-05-25 02:40:32 +0200450 <xsl:attribute name="type" select="'struct'"></xsl:attribute> <!-- STRUCT vs. LEX for morpho -->
bansp5f841732022-03-16 06:27:31 +0100451 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
bansp3e5b20c2022-03-18 20:22:31 +0100452 <xsl:attribute name="name" select="'name'"/>
453 <xsl:value-of select="local-name()"/>
bansp5f841732022-03-16 06:27:31 +0100454 </xsl:element>
455 <xsl:if test="count(@*)">
456 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
457 <xsl:attribute name="name" select="'attr'"/>
458 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
459 <xsl:attribute name="type" select="'attr'"/>
460 <xsl:for-each select="@*">
461 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
462 <xsl:attribute name="name" select="local-name(.)"/>
463 <xsl:value-of select="."/>
464 </xsl:element>
465 </xsl:for-each>
466 </xsl:element>
467 </xsl:element>
468 </xsl:if>
469 </xsl:element>
470 </xsl:element>
Piotr Banskia51907c2022-05-25 15:09:41 +0200471 <xsl:apply-templates mode="struct"/>
bansp5f841732022-03-16 06:27:31 +0100472 </xsl:template>
473
474 <!-- ************************** morpho ******************* -->
475
476 <xsl:template name="create_morpho">
banspe726b4a2022-03-28 05:47:45 +0200477 <xsl:param name="compoundID" as="xs:string"/>
bansp3e5b20c2022-03-18 20:22:31 +0100478 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100479 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
480 <xsl:param name="target" as="xs:string"/>
481
482 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
483 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
484 <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 +0100485 <xsl:element name="layer" namespace="{$KorAP_namespace}">
486 <xsl:attribute name="docid" select="$compoundID"/>
487 <xsl:attribute name="version" select="$KorAP-XML_version"/>
488
489 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
490 <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="morpho">
Piotr Banskia51907c2022-05-25 15:09:41 +0200491 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()" tunnel="yes"/>
bansp3e5b20c2022-03-18 20:22:31 +0100492 </xsl:apply-templates>
493 </xsl:element>
494 </xsl:element>
bansp5f841732022-03-16 06:27:31 +0100495 </xsl:result-document>
496 </xsl:template>
497
bansp3e5b20c2022-03-18 20:22:31 +0100498 <xsl:template match="tei:seg" mode="morpho">
Piotr Banskia51907c2022-05-25 15:09:41 +0200499 <xsl:param name="ann_morphosyntax.xml" as="document-node()" tunnel="yes"/>
500 <!-- it's so spread out because I wanted to make sure to be able to look up the individual
501 constituent values, should anything go wrong; it might get compacted at some point, but
502 the increase in efficiency will probably be minimal, compared to the decrease of readability -->
503 <xsl:variable name="offsets" as="xs:integer+">
Piotr Banski8d2609a2022-05-28 17:08:49 +0200504 <xsl:sequence select="map:get(fn:accumulator-after('elem-offset-seq')[last()], string(@xml:id))"/>
Piotr Banskia51907c2022-05-25 15:09:41 +0200505 </xsl:variable>
bansp3e5b20c2022-03-18 20:22:31 +0100506 <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
507 <xsl:variable name="my_id" select="@xml:id" as="xs:string"/>
508 <xsl:variable name="my_morph-seg" as="node()" select="$ann_morphosyntax.xml//tei:seg[substring-after(@corresp,'#') eq $my_id]"/>
509 <xsl:variable name="my_disamb" select="$my_morph-seg//tei:fs/tei:f[@name eq 'disamb']" as="node()"/>
510 <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/>
511 <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()"/>
512 <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/>
Piotr Banskia51907c2022-05-25 15:09:41 +0200513 <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>
bansp3e5b20c2022-03-18 20:22:31 +0100514
bansp3e5b20c2022-03-18 20:22:31 +0100515 <xsl:element name="span" namespace="{$KorAP_namespace}">
Piotr Banskia51907c2022-05-25 15:09:41 +0200516 <xsl:attribute name="id" select="'m' || $my_index"/>
517 <xsl:attribute name="from" select="$offsets[1]"/>
518 <xsl:attribute name="to" select="$offsets[2]"/>
bansp3e5b20c2022-03-18 20:22:31 +0100519 <xsl:attribute name="l" select="f:compute_nesting(.)"/>
520 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
521 <xsl:attribute name="type" select="'lex'"/>
522 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
523 <xsl:attribute name="name" select="'lex'"/>
524 <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0">
525 <xsl:comment select="$my_morph-seg//tei:fs/tei:f[@name eq 'orth']/tei:string"/>
Piotr Banskia51907c2022-05-25 15:09:41 +0200526
bansp3e5b20c2022-03-18 20:22:31 +0100527 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
528 <xsl:attribute name="name" select="'lemma'"/>
529 <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'base']/tei:string"/>
530 </xsl:element>
531 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
532 <xsl:attribute name="name" select="'pos'"/>
533 <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'ctag']/tei:symbol/@value"/>
534 </xsl:element>
535 <xsl:if test="string-length($chosen-msd)">
536 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
537 <xsl:attribute name="name" select="'msd'"/>
538 <xsl:value-of select="$chosen-msd"/>
539 </xsl:element>
540 </xsl:if>
541 <xsl:if test="$my_morph-seg//tei:fs/tei:f[@name eq 'nps']">
542 <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0">
543 <xsl:attribute name="name" select="'join'"/>
544 <xsl:value-of select="'left'"/>
545 </xsl:element>
546 </xsl:if>
547 </xsl:element>
548 </xsl:element>
549 </xsl:element>
550 </xsl:element>
bansp3e5b20c2022-03-18 20:22:31 +0100551 </xsl:template>
banspe726b4a2022-03-28 05:47:45 +0200552
Piotr Banskic5950ce2022-05-27 15:07:08 +0200553 <!-- ************************** named entities ******************* -->
554
555 <xsl:template name="create_named">
556 <xsl:param name="compoundID" as="xs:string"/>
557 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
558 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
559 <xsl:param name="ann_named.xml" as="document-node()"/>
560 <xsl:param name="target" as="xs:string"/>
561
562 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
563 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
564 <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>
565 <xsl:element name="layer" namespace="{$KorAP_namespace}">
566 <xsl:attribute name="docid" select="$compoundID"/>
567 <xsl:attribute name="version" select="$KorAP-XML_version"/>
568
569 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
570 <!--<xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="named">
571 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()" tunnel="yes"/>
572 <xsl:with-param name="ann_named.xml" select="$ann_named.xml" as="document-node()" tunnel="yes"/>
573 </xsl:apply-templates>-->
574 </xsl:element>
575 </xsl:element>
576 </xsl:result-document>
577 </xsl:template>
578
579 <!-- ************************** syntactic chunks ******************* -->
580
581 <xsl:template name="create_groups">
582 <xsl:param name="compoundID" as="xs:string"/>
583 <xsl:param name="ann_segmentation.xml" as="document-node()"/>
584 <xsl:param name="ann_morphosyntax.xml" as="document-node()"/>
585 <xsl:param name="ann_words.xml" as="document-node()"/>
586 <xsl:param name="ann_groups.xml" as="document-node()"/>
587 <xsl:param name="target" as="xs:string"/>
588
589 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
590 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
591 <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>
592 <xsl:element name="layer" namespace="{$KorAP_namespace}">
593 <xsl:attribute name="docid" select="$compoundID"/>
594 <xsl:attribute name="version" select="$KorAP-XML_version"/>
595
596 <xsl:element name="spanList" namespace="{$KorAP_namespace}">
597 <!--<xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="groups">
598 <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()" tunnel="yes"/>
599 <xsl:with-param name="ann_words.xml" select="$ann_words.xml" as="document-node()" tunnel="yes"/>
600 <xsl:with-param name="ann_groups.xml" select="$ann_groups.xml" as="document-node()" tunnel="yes"/>
601 </xsl:apply-templates>-->
602 </xsl:element>
603 </xsl:element>
604 </xsl:result-document>
605 </xsl:template>
606
bansp5f841732022-03-16 06:27:31 +0100607 <!-- ************************** TEXT header ******************* -->
608
609 <xsl:template name="create_text_header">
610 <xsl:param name="text.xml" as="document-node()"/>
banspe726b4a2022-03-28 05:47:45 +0200611 <xsl:param name="compoundID" as="xs:string"/>
bansp5f841732022-03-16 06:27:31 +0100612 <xsl:param name="target" as="xs:string"/>
613
614 <!-- create the local header.xml file -->
615 <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
616 xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}">
617
618 <idsHeader type="document" pattern="text" status="new" version="1.1" TEIform="teiHeader">
banspe726b4a2022-03-28 05:47:45 +0200619 <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:*" mode="text">
620 <xsl:with-param name="compoundID" as="xs:string" select="$compoundID" tunnel="yes"/>
621 </xsl:apply-templates>
bansp5f841732022-03-16 06:27:31 +0100622 </idsHeader>
623 </xsl:result-document>
624 </xsl:template>
625
626 <xsl:template match="tei:fileDesc" mode="text">
bansp9103aab2022-03-19 05:10:21 +0100627 <xsl:element name="{local-name()}">
bansp5f841732022-03-16 06:27:31 +0100628 <xsl:apply-templates mode="text"/>
bansp9103aab2022-03-19 05:10:21 +0100629 </xsl:element>
bansp5f841732022-03-16 06:27:31 +0100630 </xsl:template>
631
632 <xsl:template match="tei:title" mode="text">
633 <t.title>
634 <xsl:apply-templates/>
635 </t.title>
636 </xsl:template>
637
638 <xsl:template match="tei:titleStmt" mode="text">
banspe726b4a2022-03-28 05:47:45 +0200639 <xsl:param name="compoundID" as="xs:string" tunnel="yes"/>
bansp5f841732022-03-16 06:27:31 +0100640 <titleStmt>
641 <textSigle>
banspe726b4a2022-03-28 05:47:45 +0200642 <xsl:value-of select="$compoundID"/>
bansp5f841732022-03-16 06:27:31 +0100643 </textSigle>
644 <xsl:apply-templates mode="text"/>
645 </titleStmt>
646 </xsl:template>
647
bansp9103aab2022-03-19 05:10:21 +0100648 <xsl:template match="tei:publicationStmt" mode="text">
649 <xsl:element name="{local-name()}">
650 <xsl:apply-templates mode="text"/>
651 </xsl:element>
652 </xsl:template>
653
654 <xsl:template match="tei:availability" mode="text">
655 <xsl:element name="{local-name()}">
656 <xsl:apply-templates mode="text" select="@* | *"/>
657 </xsl:element>
658 </xsl:template>
659
660 <xsl:template match="tei:profileDesc" mode="text">
661 <xsl:element name="{local-name()}">
662 <xsl:apply-templates mode="text"/>
663 </xsl:element>
664 </xsl:template>
bansp5f841732022-03-16 06:27:31 +0100665
bansp9103aab2022-03-19 05:10:21 +0100666 <xsl:template match="tei:textClass" mode="text">
667 <xsl:element name="{local-name()}">
668 <xsl:apply-templates mode="text" select="@* | *"/>
669 </xsl:element>
670 </xsl:template>
671
672 <xsl:template match="tei:catRef" mode="text corpus">
673 <xsl:element name="{local-name()}">
674 <xsl:apply-templates mode="text" select="@* | *"/>
675 </xsl:element>
676 </xsl:template>
677
678 <xsl:template match="@status | @scheme | @target | @type | @xml:id[ancestor::tei:classDecl] | @xml:lang" mode="text corpus">
679 <xsl:copy-of select="."/>
680 </xsl:template>
681
682 <xsl:template match="tei:p" mode="text corpus">
683 <xsl:element name="{local-name()}">
684 <xsl:apply-templates mode="header-text"/>
685 </xsl:element>
686 </xsl:template>
687
688
689 <!-- OPTIMIZATION has to take modes into account -->
bansp5e2d1c02022-03-10 04:51:40 +0100690 <!-- ************************** CORPUS header ******************* -->
691 <xsl:template name="create_corpus_header">
692 <xsl:param name="text.xml" as="document-node()"/>
bansp5f841732022-03-16 06:27:31 +0100693 <xsl:param name="target" as="xs:string"/>
bansp5e2d1c02022-03-10 04:51:40 +0100694
695 <!-- create the corpus-level header.xml file -->
bansp5f841732022-03-16 06:27:31 +0100696 <xsl:result-document encoding="UTF-8" method="xml" indent="yes" href="{$target}">
bansp5e2d1c02022-03-10 04:51:40 +0100697
698 <!--doctype-public="{$publicDoctypeI5}"
699 doctype-system="{$systemDoctypeI5}">
700 these are, sadly, useless
701 -->
702
703 <idsHeader type="corpus" pattern="text" status="new" version="1.1" TEIform="teiHeader">
bansp9103aab2022-03-19 05:10:21 +0100704 <xsl:apply-templates select="$text.xml/tei:teiCorpus/tei:teiHeader/tei:*" mode="corpus"/>
bansp5e2d1c02022-03-10 04:51:40 +0100705 </idsHeader>
706 </xsl:result-document>
707 </xsl:template>
708
709 <xsl:template match="tei:fileDesc" mode="corpus">
bansp9103aab2022-03-19 05:10:21 +0100710 <xsl:element name="{local-name()}">
bansp5e2d1c02022-03-10 04:51:40 +0100711 <xsl:apply-templates mode="corpus"/>
bansp9103aab2022-03-19 05:10:21 +0100712 </xsl:element>
bansp5e2d1c02022-03-10 04:51:40 +0100713 </xsl:template>
bansp9103aab2022-03-19 05:10:21 +0100714
bansp5e2d1c02022-03-10 04:51:40 +0100715
716 <xsl:template match="tei:title" mode="corpus">
717 <c.title>
bansp9103aab2022-03-19 05:10:21 +0100718 <xsl:apply-templates mode="corpus" select="@*"/>
719 <xsl:apply-templates mode="header-text"/>
bansp5e2d1c02022-03-10 04:51:40 +0100720 </c.title>
721 </xsl:template>
722
723 <xsl:template match="tei:titleStmt" mode="corpus">
724 <titleStmt>
725 <korpusSigle>
726 <xsl:value-of select="$corpusID"/>
727 </korpusSigle>
728 <xsl:apply-templates mode="corpus"/>
729 </titleStmt>
730 </xsl:template>
731
bansp9103aab2022-03-19 05:10:21 +0100732 <xsl:template match="tei:publicationStmt" mode="corpus">
733 <xsl:element name="{local-name()}">
734 <xsl:apply-templates mode="corpus"/>
735 </xsl:element>
736 </xsl:template>
737
738 <xsl:template match="tei:availability" mode="corpus">
739 <xsl:element name="{local-name()}">
740 <xsl:apply-templates mode="corpus" select="@* | *"/>
741 </xsl:element>
742 </xsl:template>
743
744 <xsl:template match="tei:encodingDesc" mode="corpus">
745 <xsl:element name="{local-name()}">
746 <xsl:apply-templates mode="corpus"/>
747 </xsl:element>
748 </xsl:template>
749
750 <xsl:template match="tei:classDecl | tei:taxonomy | tei:category | tei:taxonomy/tei:bibl" mode="corpus">
751 <xsl:element name="{local-name()}">
752 <xsl:apply-templates mode="corpus" select="@* | *"/>
753 </xsl:element>
754 </xsl:template>
755
756 <xsl:template match="tei:bibl/tei:title | tei:edition | tei:desc" mode="corpus">
757 <xsl:element name="{local-name()}">
758 <xsl:apply-templates mode="corpus" select="@*"/>
759 <xsl:apply-templates mode="header-text"/>
760 </xsl:element>
761 </xsl:template>
762<!--
763 <xsl:template match="tei:textClass" mode="corpus">
764 <xsl:element name="{local-name()}">
765 <xsl:apply-templates mode="corpus" select="@* | *"/>
766 </xsl:element>
767 </xsl:template>
768
769 <xsl:template match="tei:catRef" mode="corpus">
770 <xsl:element name="{local-name()}">
771 <xsl:apply-templates mode="corpus" select="@* | *"/>
772 </xsl:element>
773 </xsl:template>
774-->
bansp5e2d1c02022-03-10 04:51:40 +0100775
776
777
778 <!-- this template can be called by the XSPEC test; TODO: find a way to call the main() template directly -->
779 <!-- I have not fully handled the param transmission, which would have to be kludged in just for the sake of XSPec,
780 because I'm disabling this for now, due to XSpec design issues; relevant links, a.o.:
781
782 https://stackoverflow.com/questions/64933277/what-is-the-cause-of-error-cannot-execute-xslresult-document-while-evaluating
783 https://www.balisage.net/Proceedings/vol25/html/Galtman01/BalisageVol25-Galtman01.html
784
785 In short: the internal design of XSpec forces kludges when one wants to use xsl:result-document in their stylesheets. But I don't
786 want to be strangled by kludges at the beginning of work, I've already lost quite a bit of time on this investigation,
787 I will therefore "just code" and then can think of externalizing bits of templates if we want to play with tests. For now,
788 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.
789
790 -->
791 <!--<xsl:template name="test_full">
792 <xsl:param name="corpusID"/>
793 <xsl:param name="docID"/>
794 <xsl:param name="textID"/>
795 <xsl:call-template name="xsl:initial-template"/>
796 </xsl:template>-->
797
Akron9a8ee3e2022-01-31 13:51:49 +0100798</xsl:stylesheet>
Piotr Banski6a4a2522022-05-24 01:16:47 +0200799
Piotr Banskifdc858a2022-05-25 02:40:32 +0200800<!-- template for serializing maps in messages <xsl:message select="('map:',serialize($map, map{'method':'adaptive'}))"/> -->