-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmir-badges-date.xsl
More file actions
68 lines (60 loc) · 2.79 KB
/
mir-badges-date.xsl
File metadata and controls
68 lines (60 loc) · 2.79 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:mirdateconverter="http://www.mycore.de/xslt/mirdateconverter"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="#all">
<xsl:import href="xslImport:badges:badges/mir-badges-date.xsl"/>
<xsl:include href="resource:xslt/badges/mir-badges-utils.xsl"/>
<xsl:template match="doc" mode="badge">
<xsl:apply-imports/>
<xsl:choose>
<xsl:when test="str[@name='mods.dateIssued'] or str[@name='mods.dateIssued.host']">
<xsl:call-template name="output-date-badge">
<xsl:with-param name="date" select="str[@name='mods.dateIssued'] | str[@name='mods.dateIssued.host']"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="field[@name='mods.dateIssued'] or field[@name='mods.dateIssued.host']">
<xsl:call-template name="output-date-badge">
<xsl:with-param name="date" select="field[@name='mods.dateIssued'] | field[@name='mods.dateIssued.host']"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="output-date-badge">
<xsl:param name="date"/>
<xsl:variable name="label">
<xsl:call-template name="format-date-label">
<xsl:with-param name="date" select="string(($date)[1])"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="output-badge">
<xsl:with-param name="class" select="'mir-badge-date'"/>
<xsl:with-param name="label" select="$label"/>
<xsl:with-param name="link" select="concat($ServletsBaseURL, 'solr/find?condQuery=*&fq=mods.dateIssued:%22', string(($date)[1]), '%22')"/>
<xsl:with-param name="tooltip" select="document('i18n:mir.date.published')/i18n/text()"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="format-date-label">
<xsl:param name="date" as="xs:string?"/>
<xsl:variable name="normalized" select="mirdateconverter:convert-date($date, 'ISO8601')"/>
<xsl:choose>
<xsl:when test="matches($normalized, '^\d{4}$')">
<xsl:value-of select="$normalized"/>
</xsl:when>
<xsl:when test="matches($normalized, '^\d{4}-\d{2}$')">
<xsl:value-of select="$normalized"/>
</xsl:when>
<xsl:when test="matches($normalized, '^\d{4}-\d{2}-\d{2}$')">
<xsl:value-of select="format-date(xs:date($normalized), '[Y0001]-[M01]-[D01]')"/>
</xsl:when>
<xsl:when test="$normalized castable as xs:dateTime">
<xsl:value-of select="format-dateTime(xs:dateTime($normalized), '[Y0001]-[M01]-[D01] [H01]:[m01]')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$normalized"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>