1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <xsl : stylesheet
3+ xmlns : xsl =" http://www.w3.org/1999/XSL/Transform"
4+ xmlns : xs =" http://www.w3.org/2001/XMLSchema"
5+ xmlns : tei =" http://www.tei-c.org/ns/1.0"
6+ xmlns : t2tf =" http://tei-2-tei-form"
7+ exclude-result-prefixes =" xs"
8+ version =" 2.0" >
9+
10+ <!--
11+ Convert TEI to a TEI form that is suitable for manuForma forms
12+ @author Adam Retter
13+ -->
14+
15+ <xsl : param name =" new" as =" xs:boolean" select =" false()" />
16+ <xsl : param name =" id" as =" xs:string" required =" yes" />
17+ <xsl : param name =" uri" as =" xs:string?" required =" yes" />
18+ <xsl : param name =" user-id" as =" xs:string" select =" 'guest'" />
19+ <xsl : param name =" user-name" as =" xs:string" select =" 'Guest'" />
20+
21+
22+ <xsl : import href =" tei-to-markdown.xslt" />
23+
24+ <xsl : output method =" xml" version =" 1.0" omit-xml-declaration =" no" encoding =" UTF-8" indent =" yes" />
25+
26+
27+ <xsl : template match =" tei:TEI" >
28+ <xsl : copy >
29+ <xsl : apply-templates select =" node()|@*[local-name() ne 'class']" />
30+ </xsl : copy >
31+ </xsl : template >
32+
33+ <xsl : template match =" tei:note|tei:summary[not(parent::tei:layoutDesc)]|tei:quote" >
34+ <xsl : copy >
35+ <xsl : apply-templates select =" @*" />
36+ <xsl : apply-templates select =" node()" mode =" tei-to-markdown" />
37+ </xsl : copy >
38+ </xsl : template >
39+
40+ <xsl : template match =" tei:ab[@type eq 'factoid'][@subtype eq 'relation']" >
41+ <xsl : call-template name =" copy-with-updated-id-and-source" >
42+ <xsl : with-param name =" id" select =" concat('factoid-', $id)" />
43+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
44+ </xsl : call-template >
45+ </xsl : template >
46+
47+ <xsl : template match =" tei:ab" >
48+ <xsl : copy >
49+ <xsl : apply-templates select =" @*" />
50+ <xsl : apply-templates select =" node()" mode =" tei-to-markdown" />
51+ </xsl : copy >
52+ </xsl : template >
53+
54+ <!-- Add a Contributor into the titleStmt Element -->
55+ <xsl : template match =" tei:titleStmt" >
56+ <xsl : copy >
57+ <xsl : apply-templates select =" @*" />
58+ <xsl : apply-templates select =" tei:title,tei:author" />
59+ <xsl : apply-templates select =" tei:editor" />
60+ <xsl : if test =" $user-id ne 'guest' and empty(preceding-sibling::tei:editor[. eq $user-name])" >
61+ <tei : editor xml : id =" {$user-id}" role =" contributor" ><xsl : value-of select =" $user-name" /></tei : editor >
62+ </xsl : if >
63+ <xsl : apply-templates select =" tei:meeting,tei:respStmt" />
64+ </xsl : copy >
65+ </xsl : template >
66+
67+ <xsl : template match =" tei:idno[parent::tei:ab[@type eq 'factoid'][@subtype eq 'relation']]" >
68+ <xsl : call-template name =" copy-with-updated-id-and-source" >
69+ <xsl : with-param name =" id" select =" concat('name-', count(preceding-sibling::tei:idno) + 1)" />
70+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
71+ </xsl : call-template >
72+ </xsl : template >
73+
74+ <xsl : template match =" tei:idno[parent::tei:publicationStmt]" >
75+ <xsl : copy >
76+ <xsl : apply-templates select =" node()|@*" />
77+ <xsl : if test =" $new" >
78+ <xsl : value-of select =" $uri" />
79+ </xsl : if >
80+ </xsl : copy >
81+ </xsl : template >
82+
83+ <xsl : template match =" tei:place[parent::tei:listPlace]" >
84+ <xsl : call-template name =" copy-with-updated-id-and-source" >
85+ <xsl : with-param name =" id" select =" concat('place-', $id)" />
86+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
87+ </xsl : call-template >
88+ </xsl : template >
89+
90+ <xsl : template match =" tei:placeName[parent::tei:place/parent::tei:listPlace]" >
91+ <xsl : call-template name =" copy-with-updated-id-and-source" >
92+ <xsl : with-param name =" id" select =" concat('name-', count(preceding-sibling::tei:placeName) + 1)" />
93+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
94+ </xsl : call-template >
95+ </xsl : template >
96+
97+ <xsl : template match =" tei:bibl[parent::tei:place/parent::tei:listPlace or parent::tei:person/parent::tei:listPerson or parent::tei:note/parent::tei:bibl/parent::tei:body or parent::tei:bibl/parent::tei:bibl/parent::tei:body]" >
98+ <xsl : copy >
99+ <xsl : apply-templates select =" @*[name(.) ne 'source']" />
100+ <!-- xsl:attribute name="xml:id" select="concat('bibl-', count(preceding-sibling::tei:bibl) + 1)"/ -->
101+ <xsl : apply-templates select =" node()" />
102+ </xsl : copy >
103+ </xsl : template >
104+
105+ <xsl : template match =" tei:bibl[parent::tei:body/parent::tei:text]" >
106+ <xsl : copy >
107+ <xsl : apply-templates select =" @*[name(.) ne 'source']" />
108+ <!-- xsl:attribute name="xml:id" select="concat('work-', $id)"/ -->
109+ <xsl : apply-templates select =" node()" />
110+ </xsl : copy >
111+ </xsl : template >
112+
113+ <xsl : template match =" tei:bibl[parent::tei:listBibl/parent::tei:additional/parent::tei:msDesc]" >
114+ <xsl : copy >
115+ <xsl : apply-templates select =" @*[name(.) ne 'source']" />
116+ <!-- xsl:attribute name="xml:id" select="concat('bibl-', (count(parent::tei:listBibl/parent::tei:additional/preceding-sibling::tei:additional) + 1), (count(parent::tei:listBibl/preceding-sibling::tei:listBibl) + 1), (count(preceding-sibling::tei:bibl) + 1))"/ -->
117+ <xsl : apply-templates select =" node()" />
118+ </xsl : copy >
119+ </xsl : template >
120+
121+ <xsl : template match =" tei:title[parent::tei:bibl/parent::tei:body]" >
122+ <xsl : call-template name =" copy-with-updated-id-and-source" >
123+ <xsl : with-param name =" id" select =" concat('title-', count(preceding-sibling::tei:title) + 1)" />
124+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
125+ </xsl : call-template >
126+ </xsl : template >
127+
128+ <xsl : template match =" tei:person[parent::tei:listPerson]" >
129+ <xsl : call-template name =" copy-with-updated-id-and-source" >
130+ <xsl : with-param name =" id" select =" concat('person-', $id)" />
131+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
132+ </xsl : call-template >
133+ </xsl : template >
134+
135+ <xsl : template match =" tei:persName[parent::tei:person/parent::tei:listPerson]" >
136+ <xsl : call-template name =" copy-with-updated-id-and-source" >
137+ <xsl : with-param name =" id" select =" concat('name-', count(preceding-sibling::tei:persName) + 1)" />
138+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
139+ </xsl : call-template >
140+ </xsl : template >
141+
142+ <xsl : template match =" tei:msDesc[parent::tei:person/parent::tei:listPerson]" >
143+ <xsl : call-template name =" copy-with-updated-id-and-source" >
144+ <xsl : with-param name =" id" select =" concat('ms-', $id)" />
145+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
146+ </xsl : call-template >
147+ </xsl : template >
148+
149+ <xsl : template match =" tei:msItem[parent::tei:msContents/parent::tei:msDesc]" >
150+ <xsl : call-template name =" copy-with-updated-id-and-source" >
151+ <xsl : with-param name =" id" select =" concat('item-', (count(parent::tei:msContents/preceding-sibling::tei:msContents) + 1), (count(preceding-sibling::tei:msItem) + 1))" />
152+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
153+ </xsl : call-template >
154+ </xsl : template >
155+
156+ <xsl : template match =" tei:layout[parent::tei:layoutDesc/parent::tei:objectDesc/parent::tei:physDesc/parent::tei:msDesc]" >
157+ <xsl : call-template name =" copy-with-updated-id-and-source" >
158+ <xsl : with-param name =" id" select =" concat('layout-', (count(parent::tei:layoutDesc/parent::tei:objectDesc/parent::tei:physDesc/preceding-sibling::tei:physDesc) + 1), (count(parent::tei:layoutDesc/parent::tei:objectDesc/preceding-sibling::tei:objectDesc) + 1), (count(parent::tei:layoutDesc/preceding-sibling::tei:layoutDesc) + 1), (count(preceding-sibling::tei:layout) + 1))" />
159+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
160+ </xsl : call-template >
161+ </xsl : template >
162+
163+ <xsl : template match =" tei:handNote[parent::tei:handDesc/parent::tei:physDesc/parent::tei:msDesc]" >
164+ <xsl : call-template name =" copy-with-updated-id-and-source" >
165+ <xsl : with-param name =" id" select =" concat('hand-', (count(parent::tei:handDesc/parent::tei:physDesc/preceding-sibling::tei:physDesc) + 1), (count(parent::tei:handDesc/preceding-sibling::tei:handDesc) + 1), (count(preceding-sibling::tei:handNote) + 1))" />
166+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
167+ </xsl : call-template >
168+ </xsl : template >
169+
170+ <xsl : template match =" tei:item[parent::tei:list/parent::tei:additions/parent::tei:physDesc/parent::tei:msDesc]" >
171+ <xsl : call-template name =" copy-with-updated-id-and-source" >
172+ <xsl : with-param name =" id" select =" concat('add-', (count(parent::tei:list/parent::tei:additions/parent::tei:physDesc/preceding-sibling::tei:physDesc) + 1), (count(parent::tei:list/parent::tei:additions/preceding-sibling::tei:additions) + 1), (count(parent::tei:list/preceding-sibling::tei:list) + 1), (count(preceding-sibling::tei:item) + 1))" />
173+ <xsl : with-param name =" source" select =" t2tf:extract-source(@source)" />
174+ </xsl : call-template >
175+ </xsl : template >
176+
177+ <xsl : template match =" tei:relation[tei:mutual or tei:active or tei:passive]" >
178+ <xsl : copy >
179+ <xsl : apply-templates select =" @*[not(name(.) = ('active', 'passive', 'mutual'))]" />
180+ <xsl : attribute name =" active" select =" string-join(tei:active/@ref, ' ')" />
181+ <xsl : attribute name =" passive" select =" string-join(tei:passive/@ref, ' ')" />
182+ <xsl : attribute name =" mutual" select =" string-join(tei:mutual/@ref, ' ')" />
183+ </xsl : copy >
184+ </xsl : template >
185+
186+
187+ <xsl : function name =" t2tf:extract-source" as =" xs:string" >
188+ <xsl : param name =" input" as =" xs:string" required =" yes" />
189+ <xsl : sequence select =" concat('#', tokenize($input, '#')[last()])" />
190+ </xsl : function >
191+
192+ <!-- Copies an element whilst adding or replacing its 'xml:id' and 'source' attributes -->
193+ <xsl : template name =" copy-with-updated-id-and-source" >
194+ <xsl : param name =" id" as =" xs:string" required =" yes" />
195+ <xsl : param name =" source" as =" xs:string" required =" yes" />
196+ <xsl : copy >
197+ <xsl : attribute name =" xml:id" select =" $id" />
198+ <xsl : if test =" @source[. ne '']" >
199+ <xsl : attribute name =" source" select =" $source" />
200+ </xsl : if >
201+ <xsl : apply-templates select =" @*[not(name(.) = ('xml:id', 'source'))]|node()" />
202+ </xsl : copy >
203+ </xsl : template >
204+
205+
206+ <!-- Default: Identity trasform everything whilst updating the 'source' attribute -->
207+ <xsl : template match =" node()|@*" >
208+ <xsl : copy >
209+ <xsl : apply-templates select =" @*[name(.) ne 'source']" />
210+ <xsl : if test =" @source[. ne '']" >
211+ <xsl : attribute name =" source" select =" concat('#', substring-after(@source, '#'))" />
212+ </xsl : if >
213+ <xsl : apply-templates select =" node()" />
214+ </xsl : copy >
215+ </xsl : template >
216+
217+ </xsl : stylesheet >
0 commit comments