Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / rdf / crm.xsl @ 187

History | View | Annotate | Download (20.2 kB)

1
<?xml version="1.0"?>
2
<xsl:stylesheet 
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
4
        xmlns="http://purl.org/NET/crm-owl#" 
5
    xmlns:crm="http://purl.org/NET/crm-owl#" 
6
    xmlns:tei="http://www.tei-c.org/ns/1.0" 
7
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
8
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
9
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
10
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
11
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12
    version="2.0" 
13
    xpath-default-namespace="http://www.tei-c.org/ns/1.0" 
14
    exclude-result-prefixes="tei rdf rdfs owl xsd crm xsl xs">
15
  
16
  <xsl:output encoding="utf-8" method="xml" indent="yes"/>
17

    
18
  <xsl:key name="persons" match="persName" use="@ref"/>
19
  <xsl:key name="Places" match="place[placeName]" use="placeName"/>
20
  <xsl:key name="Idents" 
21
	   match="crm:P131_is_identified_by"
22
	   use="crm:E82_Actor_Appellation/@rdf:about"/>
23

    
24
  <xsl:key name="Idents" 
25
	   match="crm:P87_is_identified_by"
26
	   use="crm:E48_Place_Name/@rdf:about"/>
27

    
28
  <xsl:template name="TEI">
29
    <xsl:choose>
30
      <xsl:when test="parent::*">
31
	<xsl:apply-templates/>
32
      </xsl:when>
33
      <xsl:otherwise>
34
	<xsl:call-template name="doit"/>
35
      </xsl:otherwise>
36
    </xsl:choose>
37
  </xsl:template>
38

    
39
  <xsl:template name="processAll">
40
    <xsl:call-template name="doit"/>
41
  </xsl:template>
42

    
43
  <xsl:template name="doit">
44
      <xsl:variable name="rdf1">
45
	<rdf:RDF
46
	    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
47
	    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
48
	    >
49
	  <xsl:call-template name="typology"/>
50
	  <xsl:apply-templates/>
51
	</rdf:RDF>
52
      </xsl:variable>
53
      <xsl:apply-templates select="$rdf1" mode="rdf2"/>
54
  </xsl:template>
55

    
56
  <!-- clean up pass -->
57

    
58
  <xsl:template match="crm:*[crm:E53_Place]" mode="rdf2">
59
    <xsl:copy>
60
      <xsl:attribute name="rdf:resource"
61
			 select="crm:E53_Place/@rdf:about"/>
62
    </xsl:copy>
63
  </xsl:template>
64

    
65
  <xsl:template match="crm:E53_Place" mode="rdf2"/>
66

    
67
  <xsl:template match="crm:E53_Place" mode="rdf3">
68
     <xsl:copy>
69
      <xsl:apply-templates  select="*|@*|processing-instruction()|comment()|text()"
70
	  mode="rdf2"/>
71
     </xsl:copy>    
72
  </xsl:template>
73

    
74
  <xsl:template match="rdf:RDF" mode="rdf2">
75
     <xsl:copy>
76
      <xsl:apply-templates  select="*|@*|processing-instruction()|comment()|text()"
77
	  mode="rdf2"/>
78
     <xsl:apply-templates select=".//crm:E53_Place" mode="rdf3"/>
79
     </xsl:copy>
80
  </xsl:template>
81

    
82
  <xsl:template match="*" mode="rdf2">
83
     <xsl:copy>
84
      <xsl:apply-templates
85
	  select="*|@*|processing-instruction()|comment()|text()"
86
	  mode="rdf2"/>
87
     </xsl:copy>
88
   </xsl:template>
89
   
90
   <xsl:template match="text()|comment()|@*|processing-instruction()"
91
		 mode="rdf2">
92
     <xsl:copy-of select="."/>
93
   </xsl:template>
94

    
95
   <!-- normal pass -->
96
  <xsl:template name="E31">
97
    <E31_Document xmlns="http://purl.org/NET/crm-owl#" 
98
	rdf:about="{tei:makeID(.,'id')}">
99
      <xsl:apply-templates select="fileDesc"/>
100
    </E31_Document>
101
    <xsl:apply-templates select="*[not(self::fileDesc)]"/>
102
  </xsl:template>
103

    
104
  <xsl:template name="anonblock">
105
    <xsl:choose>
106
      <xsl:when test="@type='dDay'">
107
	<E5_Event rdf:about="{tei:makeID(.,'event')}">
108
	  <rdf:value>
109
	    <xsl:value-of select="."/>
110
	  </rdf:value>
111
	  <xsl:apply-templates/>
112
	</E5_Event>
113
      </xsl:when>
114
    </xsl:choose>
115
  </xsl:template>
116
  
117

    
118
  <xsl:template name="teiname">
119
    <xsl:choose>
120
      <xsl:when test="@type='place'">
121
        <xsl:call-template name="E53"/>
122
      </xsl:when>
123
      <xsl:when test="@type='person'">
124
        <xsl:call-template name="E21"/>
125
      </xsl:when>
126
    </xsl:choose>
127
  </xsl:template>
128

    
129
  <xsl:template name="E53">
130
      <xsl:choose>
131
	<xsl:when test="ancestor::state"/>	
132
	<xsl:when test="ancestor::trait"/>
133
	<xsl:when test="parent::p"/>
134
	<xsl:otherwise>
135
	  <E53_Place  xmlns="http://purl.org/NET/crm-owl#" >
136
	    <xsl:attribute name="rdf:about" select="tei:makeID(.,'place')"/>
137
	    <xsl:apply-templates select="*[not(self::place or self::listPlace)]"/>
138
	    <xsl:for-each select="parent::place[1]">
139
	      <P89_falls_within rdf:resource="{tei:makeID(.,'place')}"/>
140
	    </xsl:for-each>
141
	  </E53_Place>
142
	</xsl:otherwise>
143
      </xsl:choose>
144
      <xsl:apply-templates select="place|listPlace"/>
145
  </xsl:template>
146

    
147
  <xsl:template name="E21">
148
    <xsl:choose>
149
      <xsl:when test="self::name">
150
	<P131_is_identified_by  xmlns="http://purl.org/NET/crm-owl#"
151
	      rdf:resource="{tei:makeID(.,'persname')}"/>
152
      </xsl:when>
153
      <xsl:otherwise>
154
	<E21_Person rdf:about="{tei:makeID(.,'person')}">
155
	  <xsl:apply-templates/>
156
	</E21_Person>
157
      </xsl:otherwise>
158
    </xsl:choose>
159

    
160
  </xsl:template>
161

    
162
  <xsl:template name="E74">
163
    <E74_Group xmlns="http://purl.org/NET/crm-owl#" rdf:about="{tei:makeID(.,'org')}">
164
      <xsl:apply-templates/>
165
    </E74_Group>
166
  </xsl:template>
167

    
168
  <xsl:template name="E5">
169
    <P11i_participated_in  xmlns="http://purl.org/NET/crm-owl#" >
170
      <E5_Event rdf:about="{tei:makeID(.,'event')}">
171
	<rdf:value>
172
	  <xsl:value-of select="."/>
173
	</rdf:value>
174
	<xsl:apply-templates/>
175
      </E5_Event>
176
    </P11i_participated_in>
177
  </xsl:template>
178

    
179
  <xsl:template name="E47">
180
    <P87_is_identified_by  xmlns="http://purl.org/NET/crm-owl#" >
181
      <E47_Place_Spatial_Coordinates rdf:about="{tei:makeID(.,'placecoords')}">
182
	<rdf:value>
183
	  <xsl:value-of select="."/>
184
	</rdf:value>
185
      </E47_Place_Spatial_Coordinates>
186
    </P87_is_identified_by>
187
  </xsl:template>
188

    
189
  <xsl:template name="E69">
190
    <P100i_died_in  xmlns="http://purl.org/NET/crm-owl#" >
191
      <E69_Death>
192
	<P4_has_time-span>
193
	  <E52_Time-Span>
194
	    <P82_at_some_time_within>
195
	      <E61_Time_Primitive>
196
		<xsl:call-template name="calc-date-value"/>
197
	      </E61_Time_Primitive>
198
	    </P82_at_some_time_within>
199
	  </E52_Time-Span>
200
	</P4_has_time-span>
201
      </E69_Death>
202
    </P100i_died_in>
203
  </xsl:template>
204

    
205
  <xsl:template name="E52">
206
    <xsl:choose>
207
      <xsl:when test="parent::residence"/>
208

    
209
      <xsl:when test="parent::creation"/>
210

    
211
      <xsl:when test="parent::p"/>
212

    
213
      <xsl:otherwise>
214
	<P4_has_time-span  xmlns="http://purl.org/NET/crm-owl#" >
215
	  <E52_Time-Span>
216
	    <P82_at_some_time_within>
217
	      <E61_Time_Primitive>
218
		<xsl:call-template name="calc-date-value"/>
219
	      </E61_Time_Primitive>
220
	    </P82_at_some_time_within>
221
	  </E52_Time-Span>
222
	</P4_has_time-span>
223
      </xsl:otherwise>
224
    </xsl:choose>
225
  </xsl:template>
226

    
227
  <xsl:template name="E67">
228
    <P98i_was_born  xmlns="http://purl.org/NET/crm-owl#" >
229
      <E67_Birth>
230
	<P4_has_time-span>
231
	  <E52_Time-Span>
232
	    <P82_at_some_time_within>
233
	      <E61_Time_Primitive>
234
		<xsl:call-template name="calc-date-value"/>
235
	      </E61_Time_Primitive>
236
	    </P82_at_some_time_within>
237
	  </E52_Time-Span>
238
	</P4_has_time-span>
239
	<xsl:choose>
240
	  <xsl:when test="placeName">
241
	    <P7_took_place_at>
242
	      <E53_Place rdf:about="{tei:makeID(.,'place')}">
243
		<P87_is_identified_by>
244
		  <xsl:copy-of select="@xml:lang"/>
245
		  <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
246
		    <rdf:value>
247
		      <xsl:value-of select="normalize-space(.)"/>
248
		    </rdf:value>
249
		  </E48_Place_Name>
250
		</P87_is_identified_by>
251
	      </E53_Place>
252
	    </P7_took_place_at>
253
	  </xsl:when>
254
	</xsl:choose>
255
      </E67_Birth>
256
    </P98i_was_born>
257
  </xsl:template>
258

    
259
  <xsl:template name="E82">
260
    <xsl:choose>
261
      <xsl:when test="parent::change"/>
262
      <xsl:when test="parent::person">
263
	<P131_is_identified_by  xmlns="http://purl.org/NET/crm-owl#" >
264
	  <xsl:copy-of select="@xml:lang"/>
265
	  <E82_Actor_Appellation  rdf:about="{tei:makeID(.,'persname')}">
266
	    <rdf:value>
267
	      <xsl:value-of select="normalize-space(.)"/>
268
	    </rdf:value>
269
	  </E82_Actor_Appellation>
270
	</P131_is_identified_by>
271
      </xsl:when>
272
      <xsl:when test="self::name or ancestor::event or ancestor::ab[@type='dDay']">
273
	<P11_had_participant>
274
	  <xsl:choose>
275
	    <xsl:when test="@ref">
276
	      <xsl:attribute name="rdf:resource" select="resolve-uri(@ref,base-uri(ancestor::tei:TEI))"/>
277
	    </xsl:when>
278
	    <xsl:otherwise>
279
	      <E21_Person rdf:about="{tei:makeID(.,'person')}">
280
		<P131_is_identified_by>
281
		  <E82_Actor_Appellation rdf:about="{tei:makeID(.,'persname')}">
282
		    <rdf:value>
283
		      <xsl:value-of select="normalize-space(.)"/>
284
		    </rdf:value>
285
		  </E82_Actor_Appellation>
286
		</P131_is_identified_by>
287
	      </E21_Person>
288
	    </xsl:otherwise>
289
	  </xsl:choose>
290
	</P11_had_participant>
291
      </xsl:when>
292

    
293
      <xsl:when test="parent::label"/>
294
      <xsl:when test="parent::desc"/>
295
      <xsl:when test="not(@ref)">
296
	<E21_Person rdf:about="{tei:makeID(.,'person')}">
297
	  <P131_is_identified_by>
298
	    <xsl:copy-of select="@xml:lang"/>
299
	    <E82_Actor_Appellation  rdf:about="{tei:makeID(.,'persname')}">
300
	      <rdf:value>
301
		<xsl:value-of select="normalize-space(.)"/>
302
	      </rdf:value>
303
	    </E82_Actor_Appellation>
304
	  </P131_is_identified_by>
305
	</E21_Person>
306
      </xsl:when>
307
      <xsl:when test="generate-id(.) = generate-id(key('persons',@ref)[1])">
308
	<E21_Person rdf:about="{tei:makeID(.,'person')}">
309
	  <P131_is_identified_by>
310
	    <xsl:copy-of select="@xml:lang"/>
311
	    <E82_Actor_Appellation  rdf:about="{tei:makeID(.,'persname')}">
312
	      <rdf:value>
313
		<xsl:value-of select="normalize-space(.)"/>
314
	      </rdf:value>
315
	    </E82_Actor_Appellation>
316
	  </P131_is_identified_by>
317
	</E21_Person>
318
      </xsl:when>
319
    </xsl:choose>
320
  </xsl:template>
321

    
322
  <xsl:template name="E48">
323
    <xsl:choose>
324
      <xsl:when test=".=''"/>
325
      <xsl:when test="parent::label"/>
326
      <xsl:when test="parent::desc"/>
327
      <xsl:when test="parent::tei:location"/>
328
      <xsl:when test="parent::place">
329
	<P87_is_identified_by  xmlns="http://purl.org/NET/crm-owl#" >
330
	  <xsl:copy-of select="@xml:lang"/>
331
	  <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
332
	    <rdf:value>
333
	      <xsl:value-of select="normalize-space(.)"/>
334
	    </rdf:value>
335
	  </E48_Place_Name>
336
	</P87_is_identified_by>
337
      </xsl:when>
338
      <xsl:when test="district|settlement|region|country|bloc">
339
	<xsl:call-template name="placeHierarchy">
340
	  <xsl:with-param name="next">district</xsl:with-param>
341
	</xsl:call-template>
342
      </xsl:when>
343
      <xsl:when test="self::name or ancestor::event  or ancestor::ab[@type='dDay']">
344
	<P7_took_place_at  xmlns="http://purl.org/NET/crm-owl#" >
345
	  <xsl:choose>
346
	    <xsl:when test="@ref">
347
	      <xsl:attribute name="rdf:resource" select="resolve-uri(@ref,base-uri(ancestor::tei:TEI))"/>
348
	    </xsl:when>
349
	    <xsl:otherwise>
350
	      <E53_Place rdf:about="{tei:makeID(.,'place')}"  xmlns="http://purl.org/NET/crm-owl#" >
351
		<P87_is_identified_by>
352
		  <xsl:copy-of select="@xml:lang"/>
353
		  <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
354
		    <rdf:value>
355
		      <xsl:value-of select="normalize-space(.)"/>
356
		    </rdf:value>
357
		  </E48_Place_Name>
358
		</P87_is_identified_by>
359
	      </E53_Place>
360
	    </xsl:otherwise>
361
	  </xsl:choose>
362
	</P7_took_place_at>
363
      </xsl:when>
364
      <xsl:otherwise>
365
	<E53_Place rdf:about="{tei:makeID(.,'place')}"  xmlns="http://purl.org/NET/crm-owl#" >
366
	  <P87_is_identified_by>
367
	    <xsl:copy-of select="@xml:lang"/>
368
	    <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
369
	      <rdf:value>
370
		<xsl:value-of select="normalize-space(.)"/>
371
	      </rdf:value>
372
	    </E48_Place_Name>
373
	  </P87_is_identified_by>
374
	</E53_Place>
375
      </xsl:otherwise>
376
    </xsl:choose>
377
  </xsl:template>
378

    
379
  <xsl:template name="placeHierarchy">
380
    <xsl:param name="next"/>
381
    <xsl:if test="*[local-name()=$next]">
382
      <xsl:for-each select="*[local-name()=$next][1]">
383
	<E53_Place rdf:about="{tei:makeID(.,'place')}"  xmlns="http://purl.org/NET/crm-owl#" >
384
	  <P2_has_type rdf:resource="http://www.tei-c.org/type/place/{$next}"/>
385
	  <P87_is_identified_by>
386
	    <xsl:copy-of select="@xml:lang"/>
387
	    <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
388
	      <rdf:value>
389
		<xsl:value-of select="normalize-space(.)"/>
390
	      </rdf:value>
391
	    </E48_Place_Name>
392
	  </P87_is_identified_by>
393
	  <xsl:choose>
394
	    <xsl:when test="$next='district'">
395
	      <xsl:call-template name="placeParent">
396
		<xsl:with-param name="next">settlement</xsl:with-param>
397
	      </xsl:call-template>
398
	    </xsl:when>
399
	    <xsl:when test="$next='settlement'">
400
	      <xsl:call-template name="placeParent">
401
		<xsl:with-param name="next">region</xsl:with-param>
402
	      </xsl:call-template>
403
	    </xsl:when>
404
	    <xsl:when test="$next='region'">
405
	      <xsl:call-template name="placeParent">
406
		<xsl:with-param name="next">country</xsl:with-param>
407
	      </xsl:call-template>
408
	    </xsl:when>
409
	    <xsl:when test="$next='country'">
410
	      <xsl:call-template name="placeParent">
411
		<xsl:with-param name="next">bloc</xsl:with-param>
412
	      </xsl:call-template>
413
	    </xsl:when>
414
	  </xsl:choose>
415
	</E53_Place>
416
      </xsl:for-each>
417
    </xsl:if>
418
    <xsl:choose>
419
      <xsl:when test="$next='district'">
420
	<xsl:call-template name="placeHierarchy">
421
	  <xsl:with-param name="next">settlement</xsl:with-param>
422
	</xsl:call-template>
423
      </xsl:when>
424
      <xsl:when test="$next='settlement'">
425
	<xsl:call-template name="placeHierarchy">
426
	  <xsl:with-param name="next">region</xsl:with-param>
427
	</xsl:call-template>
428
      </xsl:when>
429
      <xsl:when test="$next='region'">
430
	<xsl:call-template name="placeHierarchy">
431
	  <xsl:with-param name="next">country</xsl:with-param>
432
	</xsl:call-template>
433
      </xsl:when>
434
      <xsl:when test="$next='country'">
435
	<xsl:call-template name="placeHierarchy">
436
	  <xsl:with-param name="next">bloc</xsl:with-param>
437
	</xsl:call-template>
438
      </xsl:when>
439
    </xsl:choose>
440
  </xsl:template>
441

    
442
  <xsl:template name="placeParent">
443
    <xsl:param name="next"/>
444
    <xsl:if test="parent::*/*[local-name()=$next]">
445
      <P89_falls_within
446
	  rdf:resource="{tei:makeID(parent::*/*[local-name()=$next],'place')}"  xmlns="http://purl.org/NET/crm-owl#" />
447
    </xsl:if>
448
</xsl:template>
449
	      
450
  <xsl:template name="P74">
451
    <P74_has_current_or_former_residence  xmlns="http://purl.org/NET/crm-owl#" >
452
      <xsl:choose>
453
	<xsl:when test="placeName">
454
	  <xsl:apply-templates/>
455
	</xsl:when>
456
	<xsl:otherwise>
457
	  <E53_Place rdf:about="{tei:makeID(.,'place')}">
458
	    <P87_is_identified_by>
459
	      <xsl:copy-of select="@xml:lang"/>
460
	      <E48_Place_Name rdf:about="{tei:makeID(.,'placename')}">
461
		<rdf:value>
462
		  <xsl:value-of select="normalize-space(.)"/>
463
		</rdf:value>
464
	      </E48_Place_Name>
465
	    </P87_is_identified_by>
466
	  </E53_Place>
467
	</xsl:otherwise>
468
      </xsl:choose>
469
    </P74_has_current_or_former_residence>
470
  </xsl:template>
471

    
472
  <xsl:template name="E35">
473
    <xsl:choose>
474
      <xsl:when test="ancestor::biblFull or ancestor::bibl"/>
475
      <xsl:when test="parent::p"/>
476
      <xsl:otherwise>
477
	<P102_has_title  xmlns="http://purl.org/NET/crm-owl#" >
478
	  <E35_Title>
479
	    <rdf:value>
480
	      <xsl:value-of select="normalize-space(.)"/>
481
	    </rdf:value>
482
	  </E35_Title>
483
	</P102_has_title>
484
      </xsl:otherwise>
485
    </xsl:choose>
486
  </xsl:template>
487

    
488
  <xsl:template name="E65">
489
    <xsl:if test="not(ancestor::biblFull or ancestor::bibl)">
490
    <P94i_was_created_by  xmlns="http://purl.org/NET/crm-owl#" >
491
      <E65_Creation>
492
	<P11_had_participant>
493
	  <E21_Person rdf:about="{tei:makeID(.,'person')}">
494
	    <P131_is_identified_by>
495
	      <E82_Actor_Appellation rdf:about="{tei:makeID(.,'persname')}">
496
		<rdf:value>
497
		  <xsl:value-of select="normalize-space(.)"/>
498
		</rdf:value>
499
	      </E82_Actor_Appellation>
500
	    </P131_is_identified_by>
501
	  </E21_Person>
502
	</P11_had_participant>
503
      </E65_Creation>
504
    </P94i_was_created_by>
505
    </xsl:if>
506
  </xsl:template>
507
  
508
  <!-- general templates -->
509

    
510
  <xsl:template name="calc-date-value">
511
    <rdf:value>
512
      <xsl:choose>
513
        <xsl:when test="@when">
514
          <xsl:value-of select="@when"/>
515
        </xsl:when>
516
        <xsl:when test="@notBefore and @notAfter">
517
          <xsl:value-of select="@notBefore"/>
518
          <xsl:text> to  </xsl:text>
519
          <xsl:value-of select="@notAfter"/>
520
        </xsl:when>
521
        <xsl:when test="@notBefore">
522
          <xsl:value-of select="@notBefore"/>
523
          <xsl:text> to </xsl:text>
524
        </xsl:when>
525
        <xsl:when test="@notAfter">
526
          <xsl:text> to </xsl:text>
527
          <xsl:value-of select="@notAfter"/>
528
        </xsl:when>
529
        <xsl:otherwise>
530
          <xsl:value-of select="normalize-space(.)"/>
531
        </xsl:otherwise>
532
      </xsl:choose>
533
    </rdf:value>
534
  </xsl:template>
535

    
536
  <xsl:function name="tei:makeID" as="xs:string*">
537
    <xsl:param name="here"/>
538
    <xsl:param name="type"/>
539
    <xsl:for-each select="$here">
540
      <xsl:variable name="baseid">
541
	<xsl:choose>
542
	  <xsl:when
543
	      test="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno[starts-with(.,'http')]">
544
	    <xsl:value-of 
545
		select="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno[starts-with(.,'http')][1]"/>
546
	  </xsl:when>
547
	  <xsl:otherwise>
548
	    <xsl:choose>
549
	      <xsl:when test="ancestor-or-self::*/@xml:base">
550
		<xsl:value-of select="ancestor-or-self::*[@xml:base][1]/@xml:base"/>
551
	      </xsl:when>
552
	      <xsl:otherwise>
553
		<xsl:text>http://www.example.com</xsl:text>
554
	      </xsl:otherwise>
555
	    </xsl:choose>
556
	    <xsl:choose>
557
	      <xsl:when test="@xml:id">
558
		<xsl:value-of select="@xml:id"/>
559
	      </xsl:when>
560
	      <xsl:when
561
		  test="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno">
562
		<xsl:value-of select="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno[1]"/>
563
	      </xsl:when>
564
	      <xsl:otherwise>
565
		<xsl:number level="any"/>
566
	      </xsl:otherwise>
567
	    </xsl:choose>
568
	  </xsl:otherwise>
569
	</xsl:choose>
570
      </xsl:variable>
571
      <xsl:variable name="baseurl">
572
	<xsl:choose>
573
	  <xsl:when
574
	      test="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno[contains(.,'/id/')]">
575
	    <xsl:analyze-string
576
		select="ancestor::TEI/teiHeader/fileDesc/publicationStmt/idno[contains(.,'/id/')][1]"
577
		regex="(.*)/id/[^/]+">
578
	      <xsl:matching-substring>
579
		<xsl:value-of select="regex-group(1)"/>
580
	      </xsl:matching-substring>
581
	      <xsl:non-matching-substring>
582
		<xsl:value-of select="regex-group(0)"/>
583
	      </xsl:non-matching-substring>
584
	    </xsl:analyze-string>
585
	  </xsl:when>
586
	  <xsl:otherwise>
587
	    <xsl:choose>
588
	      <xsl:when test="ancestor-or-self::*/@xml:base">
589
		<xsl:value-of select="ancestor-or-self::*[@xml:base][1]/@xml:base"/>
590
	      </xsl:when>
591
	      <xsl:otherwise>
592
		<xsl:text>http://www.example.com</xsl:text>
593
	      </xsl:otherwise>
594
	    </xsl:choose>
595
	  </xsl:otherwise>
596
	</xsl:choose>
597
      </xsl:variable>
598
      <xsl:choose>
599
	<xsl:when test="$type='id'">
600
	  <xsl:value-of select="$baseid"/>
601
	</xsl:when>	
602
	<xsl:when test="$type='place' and @ref">
603
	  <xsl:value-of select="resolve-uri(@ref,base-uri(ancestor::tei:TEI))"/>
604
	</xsl:when>
605
	<xsl:when test="$type='person' and @ref">
606
	  <xsl:value-of select="resolve-uri(@ref,base-uri(ancestor::tei:TEI))"/>
607
	</xsl:when>
608
	<xsl:when test="$type='place' and placeName[@ref]">
609
	  <xsl:value-of select="placeName/resolve-uri(@ref,base-uri(ancestor::tei:TEI))"/>
610
	</xsl:when>
611
	<xsl:when test="$type='place' and key('Places',.)">
612
	  <xsl:value-of select="tei:makeID(key('Places',.)[1],'place')"/>
613
	</xsl:when>
614
	<xsl:when test="$type='placename' and key('Places',.)">
615
	  <xsl:value-of select="tei:makeID(key('Places',.)[1],'placename')"/>
616
	</xsl:when>
617
	<xsl:otherwise>
618
	  <xsl:variable name="composite">
619
	    <xsl:value-of select="$baseurl"/>
620
	    <xsl:text>/</xsl:text>
621
	    <xsl:value-of select="$type"/>
622
	    <xsl:text>/</xsl:text>
623
	    <xsl:choose>
624
	      <xsl:when test="@xml:id">
625
		<xsl:value-of select="@xml:id"/>
626
	      </xsl:when>
627
	      <xsl:when test="placeName[@key]">
628
		<xsl:value-of select="placeName/@key"/>
629
	      </xsl:when>
630
	      <xsl:when test="self::placeName and
631
			      parent::place[@xml:id]">
632
		<xsl:value-of select="parent::place/@xml:id"/>
633
	      </xsl:when>
634
	      <xsl:when test="self::persName and
635
			      parent::person[@xml:id]">
636
		<xsl:value-of select="parent::person/@xml:id"/>
637
	      </xsl:when>
638
	      <xsl:when test="self::placeName|self::persName|self::district|self::settlement|self::region|self::country|self::bloc">
639
		<xsl:value-of select="replace(lower-case(normalize-space(.)),'[^A-z]','')"/>
640
	      </xsl:when>
641
	      <xsl:when test="self::author">
642
		<xsl:value-of select="replace(lower-case(normalize-space(.)),'[^A-z]','')"/>
643
	      </xsl:when>
644
	      <xsl:when test="persName|placeName">
645
		<xsl:value-of select="replace(lower-case(normalize-space((persName|placeName)[1])),'[^A-z]','')"/>
646
	      </xsl:when>
647
	      <xsl:otherwise>
648
		<xsl:value-of select="generate-id()"/>
649
	      </xsl:otherwise>
650
	    </xsl:choose>
651
	  </xsl:variable>
652
	  <xsl:value-of select="$composite"/>
653
	</xsl:otherwise>
654
      </xsl:choose>
655
    </xsl:for-each>
656
  </xsl:function>
657

    
658

    
659
  
660

    
661
</xsl:stylesheet>