-
Notifications
You must be signed in to change notification settings - Fork 4
/
name.xsl
88 lines (75 loc) · 2.13 KB
/
name.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:kit="https://hananils.de/xslt/kit">
<!--
* hana+nils · Büro für Gestaltung
* https://hananils.de · [email protected]
-->
<!--
* Kit: Name
*
* This template formats a name from a node containing `firstname`, `lastname`,
* `prefix`, `title` or `suffix` nodes.
*
* # Example usage
*
* <xsl:apply-templates select="person" mode="kit:name" />
*
* # Parameters
*
* - nn
* String used if the matched node doesn't contain any personal information,
* defaults to "N. N."
* - title
* Whether the title should be included or not, defaults to false
-->
<xsl:template match="*" mode="kit:name">
<xsl:param name="nn" select="'N. N.'" />
<xsl:param name="title" select="false()" />
<!-- Get name -->
<xsl:choose>
<!-- Nomen nominandum -->
<xsl:when test="not(prefix) and not(firstname) and not(lastname) and not(suffix)">
<xsl:value-of select="$nn" />
</xsl:when>
<!-- Format name -->
<xsl:otherwise>
<!-- Title -->
<xsl:if test="$title = true() and title/text()">
<xsl:value-of select="title"/>
</xsl:if>
<!-- Prefix -->
<xsl:if test="$title = true() and title/text() and prefix/text()">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="prefix" />
<!-- First name -->
<xsl:if test="prefix/text()">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="firstname" />
<!-- Surname -->
<xsl:if test="firstname/text()">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="lastname" />
<!-- Suffix -->
<xsl:choose>
<xsl:when test="suffix != '' and not(starts-with(suffix, '('))">
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="suffix != '' and starts-with(suffix, '(')">
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="suffix = 'M.A.' or suffix = 'M. A.'">M. A.</xsl:when>
<xsl:otherwise>
<xsl:value-of select="suffix" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>