/
add_ids_to_elements.xsl
executable file
·51 lines (51 loc) · 2.28 KB
/
add_ids_to_elements.xsl
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
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
<!-- Changed version to 1.0 for xsltproc support -->
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<!-- XSLT to allocate each element in a TEI/XML document a distinct xml:id,
if that element does not already have an xml:id attribute.
Taken from an XSTL originally provided by Charlotte Tupman, Department
of Digital Humanities, King's College London, for the SAWS project
(http://www.ancientwisdoms.ac.uk) -->
<!-- In general, to extract RDF from TEI/XML documents using one of the
accompanying tei-to-rdf stylesheets, transform the TEI document using
this XSLT first, then apply a tei-to-rdf transform to this output.
This is unless you have already allocated xml:ids to every element
in your original TEI document. -->
<!-- ||||||||||||||||||||||||||||||||||||||||||||||| -->
<!-- ||||||||| copy all existing elements ||||||||| -->
<!-- ||||||||||||||||||||||||||||||||||||||||||||||| -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<!-- if the current node does not have an xml:id attribute,
generate one and add it to the XSLT output document -->
<xsl:if test="not(attribute::xml:id)">
<xsl:attribute name="xml:id">
<xsl:value-of select="concat(name(),'_',generate-id())"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||| -->
<!-- |||||||||||||||| copy processing instruction |||||||||||||||| -->
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||| -->
<xsl:template match="//processing-instruction()">
<xsl:text>
</xsl:text>
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
<xsl:text>
</xsl:text>
</xsl:template>
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||| -->
<!-- |||||||||||||||| copy all comments |||||||||||||||| -->
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||| -->
<xsl:template match="comment()">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>