-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions-workaround.xsl
112 lines (105 loc) · 5.63 KB
/
permissions-workaround.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?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"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xs"
version="3.0">
<xsl:output method="xml" encoding="UTF-8"/>
<!-- JATS elements that may have permissions associated with them -->
<xsl:variable name="permissions-elems" select="('fig','table-wrap','media','supplementary-material')"/>
<xsl:template match="*|@*|text()">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()"/>
</xsl:copy>
</xsl:template>
<!-- strip permissions elements -->
<xsl:template match="*[name()=$permissions-elems]/permissions"/>
<!-- Introduce p element for each permissions at the end of the caption -->
<xsl:template match="caption[parent::*[name()=$permissions-elems]/permissions]">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()"/>
<xsl:for-each select="parent::*/permissions">
<xsl:choose>
<xsl:when test="copyright-statement and license/license-p">
<p>
<xsl:apply-templates select="copyright-statement/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="copyright-year and copyright-holder and license/license-p">
<p>
<xsl:text>© </xsl:text>
<xsl:apply-templates select="copyright-year/(*|text())"/>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="copyright-holder/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="(copyright-year or copyright-holder) and license/license-p">
<p>
<xsl:text>© </xsl:text>
<xsl:apply-templates select="*[name()=('copyright-year','copyright-holder')]/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="license/license-p">
<p><xsl:apply-templates select="license/license-p/(*|text())"/></p>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<!-- handle objects which don't already have a caption, but do have permissions -->
<xsl:template match="*[name()=$permissions-elems and not(caption)]">
<!-- elements that must be placed before caption according to JATS DTD -->
<xsl:variable name="pre-caption-elems" select="('label','object-id')"/>
<xsl:copy>
<xsl:apply-templates select="@*|*[name()=$pre-caption-elems]|text()[not(preceding-sibling::*[not(name()=$pre-caption-elems)])]"/>
<xsl:choose>
<xsl:when test="permissions/license/license-p">
<caption>
<xsl:for-each select="permissions">
<xsl:choose>
<xsl:when test="copyright-statement and license/license-p">
<p>
<xsl:apply-templates select="copyright-statement/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="copyright-year and copyright-holder and license/license-p">
<p>
<xsl:text>© </xsl:text>
<xsl:apply-templates select="copyright-year/(*|text())"/>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="copyright-holder/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="(copyright-year or copyright-holder) and license/license-p">
<p>
<xsl:text>© </xsl:text>
<xsl:apply-templates select="*[name()=('copyright-year','copyright-holder')]/(*|text())"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates select="license/license-p/(*|text())"/>
</p>
</xsl:when>
<xsl:when test="license/license-p">
<p><xsl:apply-templates select="license/license-p/(*|text())"/></p>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
</caption>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
<xsl:apply-templates select="*[not(name()=$pre-caption-elems)]|text()[preceding-sibling::*[not(name()=$pre-caption-elems)]]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>