-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveNotes.xsl
48 lines (40 loc) · 1.32 KB
/
moveNotes.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xpath-default-namespace="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs" version="2.0">
<xsl:variable name="textId">
<xsl:value-of select="TEI/@xml:id"/>
</xsl:variable>
<xsl:template match="body//note">
<xsl:variable name="noteNum">
<xsl:value-of select="count(preceding::note) + 1"/>
</xsl:variable>
<ref xmlns="http://www.tei-c.org/ns/1.0" target="{concat('#',$textId,'_N',$noteNum)}"/>
</xsl:template>
<!-- caution! if a text already has a back, this won't work! -->
<xsl:template match="text[not(back)]">
<text xmlns="http://www.tei-c.org/ns/1.0">
<xsl:apply-templates/>
<back xmlns="http://www.tei-c.org/ns/1.0">
<div type="notes">
<xsl:for-each select="body//note">
<note>
<xsl:attribute name="xml:id">
<xsl:value-of select="concat($textId, '_N', position())"/>
</xsl:attribute>
<xsl:value-of select="."/>
</note>
<xsl:text>
</xsl:text>
</xsl:for-each>
</div>
</back>
</text>
</xsl:template>
<!-- Basically, an identity transform -->
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>