Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 3 | 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"> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 7 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 8 | <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"/> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 13 | <!-- the select is a fallback, so that it's clear to the reviewer what I'm passing in the param --> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 14 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 15 | <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" |
| 20 | select="'http://corpora.ids-mannheim.de/idsxces1/DTD/ids.xcesdoc.dtd'" as="xs:string" |
| 21 | static="true"/> |
| 22 | |
| 23 | <xsl:variable name="publicDoctypeI5" select="'-//IDS//DTD IDS-XCES 1.0//EN'" as="xs:string" |
| 24 | static="true"/> |
| 25 | |
| 26 | <xsl:variable name="KorAP_namespace" select="'http://ids-mannheim.de/ns/KorAP'" static="true" |
| 27 | as="xs:string"/> |
| 28 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 29 | <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 --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 35 | |
| 36 | <xsl:mode name="corpus" on-no-match="deep-skip"/> |
| 37 | <xsl:mode name="text" on-no-match="deep-skip"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 38 | <xsl:mode name="header-text" on-no-match="text-only-copy"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 39 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 40 | <!-- <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> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 82 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 83 | <xsl:template match="@default" mode="#all"/> |
| 84 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 85 | <xsl:template name="xsl:initial-template"> |
| 86 | <xsl:variable name="text.xml" as="document-node()" select="doc($sourceDir || 'text.xml')"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 87 | <xsl:variable name="ann_morphosyntax.xml" as="document-node()" |
| 88 | select="doc($sourceDir || 'ann_morphosyntax.xml')"/> |
| 89 | <xsl:variable name="ann_segmentation.xml" as="document-node()" |
| 90 | select="doc($sourceDir || 'ann_segmentation.xml')"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 91 | |
| 92 | <xsl:call-template name="create_data"> |
| 93 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 94 | <xsl:with-param name="target" select="$targetTextDir || 'data.xml'" as="xs:string"/> |
| 95 | </xsl:call-template> |
| 96 | |
| 97 | <xsl:call-template name="create_struct"> |
| 98 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
| 99 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 100 | as="document-node()"/> |
| 101 | <xsl:with-param name="target" select="$targetTextDir || 'struct/structure.xml'" as="xs:string" |
| 102 | /> |
| 103 | </xsl:call-template> |
| 104 | |
| 105 | <xsl:call-template name="create_morpho"> |
| 106 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 107 | <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml" |
| 108 | as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 109 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" |
| 110 | as="document-node()"/> |
| 111 | <xsl:with-param name="target" select="$targetTextDir || 'nkjp/morpho.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 112 | </xsl:call-template> |
| 113 | |
| 114 | <xsl:call-template name="create_text_header"> |
| 115 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 116 | <xsl:with-param name="target" select="$targetTextDir || 'header.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 117 | </xsl:call-template> |
| 118 | |
| 119 | <xsl:call-template name="create_corpus_header"> |
| 120 | <xsl:with-param name="text.xml" select="$text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 121 | <xsl:with-param name="target" select="$targetCorpusDir || 'header.xml'" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 122 | </xsl:call-template> |
| 123 | </xsl:template> |
| 124 | |
| 125 | <!-- ************************** data.xml ******************* --> |
| 126 | |
| 127 | <xsl:template name="create_data"> |
| 128 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 129 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 130 | <!-- create the data.xml file --> |
| 131 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 132 | xpath-default-namespace="{$KorAP_namespace}" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 133 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 134 | <xsl:processing-instruction name="xml-model">href="text.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 135 | <xsl:element name="raw_text" namespace="{$KorAP_namespace}"> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 136 | <xsl:attribute name="docid" select="$compoundID"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 137 | <xsl:element name="metadata" namespace="{$KorAP_namespace}"> |
| 138 | <xsl:attribute name="file" select="'metadata.xml'"/> |
| 139 | </xsl:element> |
| 140 | |
| 141 | <xsl:element name="text" namespace="{$KorAP_namespace}"> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 142 | <xsl:value-of select="$text.xml//*[local-name() = 'ab']"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 143 | </xsl:element> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 144 | </xsl:element> |
bansp | f79443e | 2022-02-25 14:25:33 +0100 | [diff] [blame] | 145 | </xsl:result-document> |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 146 | </xsl:template> |
| 147 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 148 | <!-- ************************** struct ******************* --> |
| 149 | |
| 150 | <xsl:template name="create_struct"> |
| 151 | <xsl:param name="text.xml" as="document-node()"/> |
| 152 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
| 153 | <xsl:param name="target" as="xs:string"/> |
| 154 | |
| 155 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 156 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 157 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
| 158 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 159 | <xsl:attribute name="docid" select="$compoundID"/> |
| 160 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 161 | |
| 162 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 163 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/> |
| 164 | </xsl:element> |
| 165 | </xsl:element> |
| 166 | </xsl:result-document> |
| 167 | </xsl:template> |
| 168 | |
| 169 | <xsl:template match="tei:*" mode="struct"> |
| 170 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 171 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 172 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 173 | <!-- I have made a major mess here, but it works... it's so spread out |
| 174 | because I wanted to make sure to be able to look up the individual |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 175 | constituent values, should anything go wrong; optimization will come when it's worked against a larger dataset --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 176 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 177 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 178 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 179 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 180 | <xsl:choose> |
| 181 | <xsl:when test="self::tei:s or self::tei:p"> |
| 182 | <xsl:choose> |
| 183 | <xsl:when test="$preceding-count"> |
| 184 | <xsl:sequence select=" |
| 185 | sum(for $p in $preceding |
| 186 | return |
| 187 | count($p/descendant::*))"/> |
| 188 | </xsl:when> |
| 189 | <xsl:otherwise> |
| 190 | <xsl:sequence select="0"/> |
| 191 | </xsl:otherwise> |
| 192 | </xsl:choose> |
| 193 | </xsl:when> |
| 194 | <xsl:otherwise> |
| 195 | <xsl:sequence select="0"/> |
| 196 | </xsl:otherwise> |
| 197 | </xsl:choose> |
| 198 | </xsl:variable> |
| 199 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 200 | as="xs:integer"/> |
| 201 | |
| 202 | <xsl:variable name="start" as="xs:integer"> |
| 203 | <xsl:choose> |
| 204 | <xsl:when test="self::tei:text or self::tei:body"> |
| 205 | <xsl:sequence select="0"/> |
| 206 | </xsl:when> |
| 207 | <xsl:when test="self::tei:p"> |
| 208 | <xsl:variable name="first_corresp" |
| 209 | select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp" |
| 210 | as="attribute(corresp)"/> |
| 211 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 212 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 213 | </xsl:when> |
| 214 | <xsl:when test="self::tei:s"> |
| 215 | <xsl:variable name="first_corresp" |
| 216 | select="descendant::tei:seg[1]/attribute::corresp" |
| 217 | as="attribute(corresp)"/> |
| 218 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 219 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 220 | </xsl:when> |
| 221 | <xsl:when test="self::tei:seg"> |
| 222 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 223 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 224 | </xsl:when> |
| 225 | </xsl:choose> |
| 226 | </xsl:variable> |
| 227 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 228 | </xsl:variable> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 229 | |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 230 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 231 | <xsl:attribute name="id" select="'s' || $my_index"/> |
| 232 | <xsl:attribute name="from" select="$start"/> |
| 233 | <xsl:attribute name="to" select="$end"/> |
| 234 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 235 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 236 | <xsl:attribute name="type" select="'struct'"></xsl:attribute> <!-- STRUCT vs. LEX --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 237 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 238 | <xsl:attribute name="name" select="'name'"/> |
| 239 | <xsl:value-of select="local-name()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 240 | </xsl:element> |
| 241 | <xsl:if test="count(@*)"> |
| 242 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 243 | <xsl:attribute name="name" select="'attr'"/> |
| 244 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 245 | <xsl:attribute name="type" select="'attr'"/> |
| 246 | <xsl:for-each select="@*"> |
| 247 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 248 | <xsl:attribute name="name" select="local-name(.)"/> |
| 249 | <xsl:value-of select="."/> |
| 250 | </xsl:element> |
| 251 | </xsl:for-each> |
| 252 | </xsl:element> |
| 253 | </xsl:element> |
| 254 | </xsl:if> |
| 255 | </xsl:element> |
| 256 | </xsl:element> |
| 257 | <xsl:apply-templates mode="struct"> |
| 258 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 259 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 260 | <xsl:with-param name="index" select="$my_index"/> |
| 261 | </xsl:apply-templates> |
| 262 | </xsl:template> |
| 263 | |
| 264 | <!-- ************************** morpho ******************* --> |
| 265 | |
| 266 | <xsl:template name="create_morpho"> |
| 267 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 268 | <xsl:param name="ann_segmentation.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 269 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 270 | <xsl:param name="target" as="xs:string"/> |
| 271 | |
| 272 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 273 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 274 | <xsl:processing-instruction name="xml-model">href="span.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"</xsl:processing-instruction> |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 275 | <xsl:element name="layer" namespace="{$KorAP_namespace}"> |
| 276 | <xsl:attribute name="docid" select="$compoundID"/> |
| 277 | <xsl:attribute name="version" select="$KorAP-XML_version"/> |
| 278 | |
| 279 | <xsl:element name="spanList" namespace="{$KorAP_namespace}"> |
| 280 | <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="morpho"> |
| 281 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 282 | </xsl:apply-templates> |
| 283 | </xsl:element> |
| 284 | </xsl:element> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 285 | </xsl:result-document> |
| 286 | </xsl:template> |
| 287 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 288 | <xsl:template match="tei:*" mode="morpho"> |
| 289 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 290 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 291 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 292 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 293 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 294 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 295 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 296 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 297 | <xsl:choose> |
| 298 | <xsl:when test="self::tei:s or self::tei:p"> |
| 299 | <xsl:choose> |
| 300 | <xsl:when test="$preceding-count"> |
| 301 | <xsl:sequence select=" |
| 302 | sum(for $p in $preceding |
| 303 | return |
| 304 | count($p/descendant::*))"/> |
| 305 | </xsl:when> |
| 306 | <xsl:otherwise> |
| 307 | <xsl:sequence select="0"/> |
| 308 | </xsl:otherwise> |
| 309 | </xsl:choose> |
| 310 | </xsl:when> |
| 311 | <xsl:otherwise> |
| 312 | <xsl:sequence select="0"/> |
| 313 | </xsl:otherwise> |
| 314 | </xsl:choose> |
| 315 | </xsl:variable> |
| 316 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 317 | as="xs:integer"/> |
| 318 | |
| 319 | <xsl:variable name="start" as="xs:integer"> |
| 320 | <xsl:choose> |
| 321 | <xsl:when test="self::tei:text or self::tei:body"> |
| 322 | <xsl:sequence select="0"/> |
| 323 | </xsl:when> |
| 324 | <xsl:when test="self::tei:p"> |
| 325 | <xsl:variable name="first_corresp" |
| 326 | select="descendant::tei:s[1]/descendant::tei:seg[1]/attribute::corresp" |
| 327 | as="attribute(corresp)"/> |
| 328 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 329 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 330 | </xsl:when> |
| 331 | <xsl:when test="self::tei:s"> |
| 332 | <xsl:variable name="first_corresp" |
| 333 | select="descendant::tei:seg[1]/attribute::corresp" |
| 334 | as="attribute(corresp)"/> |
| 335 | <xsl:variable name="numbers" select="substring-after(substring-before($first_corresp,')'),',')"/> |
| 336 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 337 | </xsl:when> |
| 338 | <!--<xsl:when test="self::tei:seg"> |
| 339 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 340 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 341 | </xsl:when>--> |
| 342 | </xsl:choose> |
| 343 | </xsl:variable> |
| 344 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 345 | </xsl:variable> |
| 346 | |
| 347 | <xsl:apply-templates mode="morpho"> |
| 348 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 349 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 350 | <xsl:with-param name="index" select="$my_index"/> |
| 351 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 352 | </xsl:apply-templates> |
| 353 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 354 | |
bansp | 3e5b20c | 2022-03-18 20:22:31 +0100 | [diff] [blame] | 355 | <xsl:template match="tei:seg" mode="morpho"> |
| 356 | <xsl:param name="ini" as="xs:integer" required="no" select="0"/> |
| 357 | <xsl:param name="fin" as="xs:integer" required="no" select="999999999"/> |
| 358 | <xsl:param name="index" as="xs:integer" required="no" select="1"/> |
| 359 | <xsl:param name="ann_morphosyntax.xml" as="document-node()"/> |
| 360 | <!-- I have made a major mess here, but it works... it's so spread out |
| 361 | because I wanted to make sure to be able to look up the individual |
| 362 | constituent values, should anything go wrong --> |
| 363 | <xsl:variable name="my_name" select="local-name()" as="xs:string"/> |
| 364 | <xsl:variable name="my_id" select="@xml:id" as="xs:string"/> |
| 365 | <xsl:variable name="my_morph-seg" as="node()" select="$ann_morphosyntax.xml//tei:seg[substring-after(@corresp,'#') eq $my_id]"/> |
| 366 | <xsl:variable name="my_disamb" select="$my_morph-seg//tei:fs/tei:f[@name eq 'disamb']" as="node()"/> |
| 367 | <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/> |
| 368 | <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()"/> |
| 369 | <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/> |
| 370 | <xsl:variable name="preceding" select="preceding-sibling::*[local-name(.) eq $my_name]"/> |
| 371 | <xsl:variable name="preceding-count" select="count($preceding)"/> |
| 372 | <xsl:variable name="outside-preceding-count" as="xs:integer"> |
| 373 | <xsl:choose> |
| 374 | <xsl:when test="self::tei:s or self::tei:p"> |
| 375 | <xsl:choose> |
| 376 | <xsl:when test="$preceding-count"> |
| 377 | <xsl:sequence select=" |
| 378 | sum(for $p in $preceding |
| 379 | return |
| 380 | count($p/descendant::*))"/> |
| 381 | </xsl:when> |
| 382 | <xsl:otherwise> |
| 383 | <xsl:sequence select="0"/> |
| 384 | </xsl:otherwise> |
| 385 | </xsl:choose> |
| 386 | </xsl:when> |
| 387 | <xsl:otherwise> |
| 388 | <xsl:sequence select="0"/> |
| 389 | </xsl:otherwise> |
| 390 | </xsl:choose> |
| 391 | </xsl:variable> |
| 392 | <xsl:variable name="my_index" select="$index + 1 + $preceding-count + $outside-preceding-count" |
| 393 | as="xs:integer"/> |
| 394 | |
| 395 | <xsl:variable name="start" as="xs:integer"> |
| 396 | <xsl:variable name="numbers" select="substring-after(substring-before(@corresp,')'),',')"/> |
| 397 | <xsl:sequence select="xs:integer(substring-before($numbers,','))"/> |
| 398 | </xsl:variable> |
| 399 | <xsl:variable name="end" as="xs:integer" select="f:calc_content_length(.)"> |
| 400 | </xsl:variable> |
| 401 | <xsl:element name="span" namespace="{$KorAP_namespace}"> |
| 402 | <xsl:attribute name="id" select="'s' || $my_index"/> |
| 403 | <xsl:attribute name="from" select="$start"/> |
| 404 | <xsl:attribute name="to" select="$end"/> |
| 405 | <xsl:attribute name="l" select="f:compute_nesting(.)"/> |
| 406 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 407 | <xsl:attribute name="type" select="'lex'"/> |
| 408 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 409 | <xsl:attribute name="name" select="'lex'"/> |
| 410 | <xsl:element name="fs" namespace="http://www.tei-c.org/ns/1.0"> |
| 411 | <xsl:comment select="$my_morph-seg//tei:fs/tei:f[@name eq 'orth']/tei:string"/> |
| 412 | |
| 413 | |
| 414 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 415 | <xsl:attribute name="name" select="'lemma'"/> |
| 416 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'base']/tei:string"/> |
| 417 | </xsl:element> |
| 418 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 419 | <xsl:attribute name="name" select="'pos'"/> |
| 420 | <xsl:value-of select="$my_choice-lex/tei:f[@name eq 'ctag']/tei:symbol/@value"/> |
| 421 | </xsl:element> |
| 422 | <xsl:if test="string-length($chosen-msd)"> |
| 423 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 424 | <xsl:attribute name="name" select="'msd'"/> |
| 425 | <xsl:value-of select="$chosen-msd"/> |
| 426 | </xsl:element> |
| 427 | </xsl:if> |
| 428 | <xsl:if test="$my_morph-seg//tei:fs/tei:f[@name eq 'nps']"> |
| 429 | <xsl:element name="f" namespace="http://www.tei-c.org/ns/1.0"> |
| 430 | <xsl:attribute name="name" select="'join'"/> |
| 431 | <xsl:value-of select="'left'"/> |
| 432 | </xsl:element> |
| 433 | </xsl:if> |
| 434 | </xsl:element> |
| 435 | </xsl:element> |
| 436 | </xsl:element> |
| 437 | </xsl:element> |
| 438 | <xsl:apply-templates mode="morpho"> |
| 439 | <xsl:with-param name="ini" select="$start" as="xs:integer"/> |
| 440 | <xsl:with-param name="fin" select="$end" as="xs:integer"/> |
| 441 | <xsl:with-param name="index" select="$my_index"/> |
| 442 | <xsl:with-param name="ann_morphosyntax.xml" select="$ann_morphosyntax.xml" as="document-node()"/> |
| 443 | </xsl:apply-templates> |
| 444 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 445 | <!-- ************************** TEXT header ******************* --> |
| 446 | |
| 447 | <xsl:template name="create_text_header"> |
| 448 | <xsl:param name="text.xml" as="document-node()"/> |
| 449 | <xsl:param name="target" as="xs:string"/> |
| 450 | |
| 451 | <!-- create the local header.xml file --> |
| 452 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" |
| 453 | xpath-default-namespace="http://ids-mannheim.de/ns/KorAP" href="{$target}"> |
| 454 | |
| 455 | <idsHeader type="document" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 456 | <xsl:apply-templates select="$text.xml//tei:TEI/tei:teiHeader/tei:*" mode="text"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 457 | </idsHeader> |
| 458 | </xsl:result-document> |
| 459 | </xsl:template> |
| 460 | |
| 461 | <xsl:template match="tei:fileDesc" mode="text"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 462 | <xsl:element name="{local-name()}"> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 463 | <xsl:apply-templates mode="text"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 464 | </xsl:element> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 465 | </xsl:template> |
| 466 | |
| 467 | <xsl:template match="tei:title" mode="text"> |
| 468 | <t.title> |
| 469 | <xsl:apply-templates/> |
| 470 | </t.title> |
| 471 | </xsl:template> |
| 472 | |
| 473 | <xsl:template match="tei:titleStmt" mode="text"> |
| 474 | <titleStmt> |
| 475 | <textSigle> |
bansp | ba37fb9 | 2022-03-22 03:34:48 +0100 | [diff] [blame] | 476 | <xsl:value-of select="$corpusID || '/' || $docID || '.' || $textID"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 477 | </textSigle> |
| 478 | <xsl:apply-templates mode="text"/> |
| 479 | </titleStmt> |
| 480 | </xsl:template> |
| 481 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 482 | <xsl:template match="tei:publicationStmt" mode="text"> |
| 483 | <xsl:element name="{local-name()}"> |
| 484 | <xsl:apply-templates mode="text"/> |
| 485 | </xsl:element> |
| 486 | </xsl:template> |
| 487 | |
| 488 | <xsl:template match="tei:availability" mode="text"> |
| 489 | <xsl:element name="{local-name()}"> |
| 490 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 491 | </xsl:element> |
| 492 | </xsl:template> |
| 493 | |
| 494 | <xsl:template match="tei:profileDesc" mode="text"> |
| 495 | <xsl:element name="{local-name()}"> |
| 496 | <xsl:apply-templates mode="text"/> |
| 497 | </xsl:element> |
| 498 | </xsl:template> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 499 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 500 | <xsl:template match="tei:textClass" mode="text"> |
| 501 | <xsl:element name="{local-name()}"> |
| 502 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 503 | </xsl:element> |
| 504 | </xsl:template> |
| 505 | |
| 506 | <xsl:template match="tei:catRef" mode="text corpus"> |
| 507 | <xsl:element name="{local-name()}"> |
| 508 | <xsl:apply-templates mode="text" select="@* | *"/> |
| 509 | </xsl:element> |
| 510 | </xsl:template> |
| 511 | |
| 512 | <xsl:template match="@status | @scheme | @target | @type | @xml:id[ancestor::tei:classDecl] | @xml:lang" mode="text corpus"> |
| 513 | <xsl:copy-of select="."/> |
| 514 | </xsl:template> |
| 515 | |
| 516 | <xsl:template match="tei:p" mode="text corpus"> |
| 517 | <xsl:element name="{local-name()}"> |
| 518 | <xsl:apply-templates mode="header-text"/> |
| 519 | </xsl:element> |
| 520 | </xsl:template> |
| 521 | |
| 522 | |
| 523 | <!-- OPTIMIZATION has to take modes into account --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 524 | <!-- ************************** CORPUS header ******************* --> |
| 525 | <xsl:template name="create_corpus_header"> |
| 526 | <xsl:param name="text.xml" as="document-node()"/> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 527 | <xsl:param name="target" as="xs:string"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 528 | |
| 529 | <!-- create the corpus-level header.xml file --> |
bansp | 5f84173 | 2022-03-16 06:27:31 +0100 | [diff] [blame] | 530 | <xsl:result-document encoding="UTF-8" method="xml" indent="yes" href="{$target}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 531 | |
| 532 | <!--doctype-public="{$publicDoctypeI5}" |
| 533 | doctype-system="{$systemDoctypeI5}"> |
| 534 | these are, sadly, useless |
| 535 | --> |
| 536 | |
| 537 | <idsHeader type="corpus" pattern="text" status="new" version="1.1" TEIform="teiHeader"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 538 | <xsl:apply-templates select="$text.xml/tei:teiCorpus/tei:teiHeader/tei:*" mode="corpus"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 539 | </idsHeader> |
| 540 | </xsl:result-document> |
| 541 | </xsl:template> |
| 542 | |
| 543 | <xsl:template match="tei:fileDesc" mode="corpus"> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 544 | <xsl:element name="{local-name()}"> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 545 | <xsl:apply-templates mode="corpus"/> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 546 | </xsl:element> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 547 | </xsl:template> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 548 | |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 549 | |
| 550 | <xsl:template match="tei:title" mode="corpus"> |
| 551 | <c.title> |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 552 | <xsl:apply-templates mode="corpus" select="@*"/> |
| 553 | <xsl:apply-templates mode="header-text"/> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 554 | </c.title> |
| 555 | </xsl:template> |
| 556 | |
| 557 | <xsl:template match="tei:titleStmt" mode="corpus"> |
| 558 | <titleStmt> |
| 559 | <korpusSigle> |
| 560 | <xsl:value-of select="$corpusID"/> |
| 561 | </korpusSigle> |
| 562 | <xsl:apply-templates mode="corpus"/> |
| 563 | </titleStmt> |
| 564 | </xsl:template> |
| 565 | |
bansp | 9103aab | 2022-03-19 05:10:21 +0100 | [diff] [blame] | 566 | <xsl:template match="tei:publicationStmt" mode="corpus"> |
| 567 | <xsl:element name="{local-name()}"> |
| 568 | <xsl:apply-templates mode="corpus"/> |
| 569 | </xsl:element> |
| 570 | </xsl:template> |
| 571 | |
| 572 | <xsl:template match="tei:availability" mode="corpus"> |
| 573 | <xsl:element name="{local-name()}"> |
| 574 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 575 | </xsl:element> |
| 576 | </xsl:template> |
| 577 | |
| 578 | <xsl:template match="tei:encodingDesc" mode="corpus"> |
| 579 | <xsl:element name="{local-name()}"> |
| 580 | <xsl:apply-templates mode="corpus"/> |
| 581 | </xsl:element> |
| 582 | </xsl:template> |
| 583 | |
| 584 | <xsl:template match="tei:classDecl | tei:taxonomy | tei:category | tei:taxonomy/tei:bibl" mode="corpus"> |
| 585 | <xsl:element name="{local-name()}"> |
| 586 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 587 | </xsl:element> |
| 588 | </xsl:template> |
| 589 | |
| 590 | <xsl:template match="tei:bibl/tei:title | tei:edition | tei:desc" mode="corpus"> |
| 591 | <xsl:element name="{local-name()}"> |
| 592 | <xsl:apply-templates mode="corpus" select="@*"/> |
| 593 | <xsl:apply-templates mode="header-text"/> |
| 594 | </xsl:element> |
| 595 | </xsl:template> |
| 596 | <!-- |
| 597 | <xsl:template match="tei:textClass" mode="corpus"> |
| 598 | <xsl:element name="{local-name()}"> |
| 599 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 600 | </xsl:element> |
| 601 | </xsl:template> |
| 602 | |
| 603 | <xsl:template match="tei:catRef" mode="corpus"> |
| 604 | <xsl:element name="{local-name()}"> |
| 605 | <xsl:apply-templates mode="corpus" select="@* | *"/> |
| 606 | </xsl:element> |
| 607 | </xsl:template> |
| 608 | --> |
bansp | 5e2d1c0 | 2022-03-10 04:51:40 +0100 | [diff] [blame] | 609 | |
| 610 | |
| 611 | |
| 612 | <!-- this template can be called by the XSPEC test; TODO: find a way to call the main() template directly --> |
| 613 | <!-- I have not fully handled the param transmission, which would have to be kludged in just for the sake of XSPec, |
| 614 | because I'm disabling this for now, due to XSpec design issues; relevant links, a.o.: |
| 615 | |
| 616 | https://stackoverflow.com/questions/64933277/what-is-the-cause-of-error-cannot-execute-xslresult-document-while-evaluating |
| 617 | https://www.balisage.net/Proceedings/vol25/html/Galtman01/BalisageVol25-Galtman01.html |
| 618 | |
| 619 | In short: the internal design of XSpec forces kludges when one wants to use xsl:result-document in their stylesheets. But I don't |
| 620 | want to be strangled by kludges at the beginning of work, I've already lost quite a bit of time on this investigation, |
| 621 | I will therefore "just code" and then can think of externalizing bits of templates if we want to play with tests. For now, |
| 622 | 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. |
| 623 | |
| 624 | --> |
| 625 | <!--<xsl:template name="test_full"> |
| 626 | <xsl:param name="corpusID"/> |
| 627 | <xsl:param name="docID"/> |
| 628 | <xsl:param name="textID"/> |
| 629 | <xsl:call-template name="xsl:initial-template"/> |
| 630 | </xsl:template>--> |
| 631 | |
Akron | 9a8ee3e | 2022-01-31 13:51:49 +0100 | [diff] [blame] | 632 | </xsl:stylesheet> |