-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeso_tei.xsl
More file actions
65 lines (64 loc) · 3.68 KB
/
theso_tei.xsl
File metadata and controls
65 lines (64 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.1" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xs t skos" version="3.0" xmlns="http://www.tei-c.org/ns/1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="no"/>
<!--
insert @ref
on persName, orgName, name, title and term elements
in a corpus of xml-tei files
based on 5 thesauri in skos : persons.xml, organizations.xml, events.xml, titles.xml, terms.xml
@ref will point to the skos:Concept if
1° the type of the entity corresponds to the thesaurus (persName against persons.xml, orgName against organizations.xml, etc.)
2° the text content of the element is the same as one of the prefLabel/altLabel of the Concept
former @ref are overwritten (or removed if there is no match in the current thesaurus)
-->
<xsl:import href="normalize.xsl"/>
<xsl:template match="t:persName | t:orgName | t:name[@type = 'manif'] | t:term | t:text//t:title | t:name[ancestor::t:titleStmt]">
<!-- get info on the current tei element -->
<!-- before comparing forms of the thesaurus and the form in the tei, normalize the later -->
<xsl:variable name="id">
<xsl:call-template name="normalize">
<xsl:with-param name="mode">transform</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- get type -->
<xsl:variable name="type">
<xsl:choose>
<xsl:when test="name() = 'name' and ancestor::t:titleStmt">team</xsl:when>
<xsl:otherwise><xsl:value-of select="name()"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy>
<xsl:for-each select="collection('thesauri/?select=*.xml')//*[self::skos:altLabel or self::skos:prefLabel]">
<!-- get info on the current thesaurus entry -->
<!-- before comparing forms of the thesaurus and the form in the tei, normalize the former -->
<xsl:variable name="thesaurus_id">
<xsl:call-template name="normalize">
<xsl:with-param name="mode">transform</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- get the thesaurus name and transform to the tei element on which it has authority -->
<xsl:variable name="filename" select="tokenize(base-uri(), '/')[last()]"/>
<xsl:variable name="thesaurus_type">
<xsl:choose>
<xsl:when test="$filename = 'persons.xml'">persName</xsl:when>
<xsl:when test="$filename = 'organizations.xml'">orgName</xsl:when>
<xsl:when test="$filename = 'events.xml'">name</xsl:when>
<xsl:when test="$filename = 'titles.xml'">title</xsl:when>
<xsl:when test="$filename = 'terms.xml'">term</xsl:when>
<xsl:when test="$filename = 'team_members.xml'">team</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- if we are in the right thesaurus for this element + form is the same, insert @ref pointing to skos:Concept/@rdf:ID -->
<xsl:if test="$thesaurus_id = $id and $thesaurus_type = $type">
<xsl:attribute name="ref">difdepo:<xsl:value-of select="$filename"/>#<xsl:value-of select="./parent::*/@rdf:ID"/></xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="* | @type | @role | processing-instruction() | comment() | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | * | processing-instruction() | comment()">
<xsl:copy>
<xsl:apply-templates select="* | @* | text() | processing-instruction() | comment()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>