-
Notifications
You must be signed in to change notification settings - Fork 0
/
name-alternatives.xsl
71 lines (66 loc) · 3.19 KB
/
name-alternatives.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
<?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"/>
<xsl:template match="*|@*|text()|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="contrib[@contrib-type='author']/name-alternatives[count(name)=2]">
<xsl:choose>
<xsl:when test="./name[@name-style='western'] and ./name[not(@name-style='western')]">
<name>
<xsl:apply-templates select="./name[@name-style='western']/*"/>
<xsl:if test="./name[not(@name-style='western')]/*">
<xsl:variable name="non-western-name" select="./name[not(@name-style='western')]"/>
<suffix>
<xsl:choose>
<xsl:when test="$non-western-name/given-names and $non-western-name/surname">
<xsl:value-of select="$non-western-name/given-names"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$non-western-name/surname"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$non-western-name/*"/>
</xsl:otherwise>
</xsl:choose>
</suffix>
</xsl:if>
</name>
</xsl:when>
<xsl:otherwise>
<name>
<xsl:apply-templates select="./name[1]/*"/>
<xsl:if test="./name[2]/*">
<xsl:variable name="second-name" select="./name[2]"/>
<suffix>
<xsl:choose>
<xsl:when test="$second-name/given-names and $second-name/surname">
<xsl:value-of select="$second-name/given-names"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$second-name/surname"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$second-name/*"/>
</xsl:otherwise>
</xsl:choose>
</suffix>
</xsl:if>
</name>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="contrib[@contrib-type='author']/name-alternatives[count(name)=1 and count(string-name)=1]">
<name>
<xsl:apply-templates select="./name/*"/>
<suffix>
<xsl:apply-templates select="./string-name/(*|text())"/>
</suffix>
</name>
</xsl:template>
</xsl:stylesheet>