source: cats/ISOcat/trunk/mod-ISOcat-interface-rest/representations/atom/DC-history.xsl @ 2912

Last change on this file since 2912 was 2912, checked in by mwindhouwer, 11 years ago

M mod-ISOcat-interface-rest/representations/atom/DC-history.xsl
M mod-ISOcat-interface-rest/representations/html/DC-history.xsl

  • removed milliseconds from the timestamp
  • fall back to unknown if the editor isn't known
File size: 3.7 KB
Line 
1<?xml version="1.0"?>
2<xsl:stylesheet
3  version="2.0"
4  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5  xmlns:xs="http://www.w3.org/2001/XMLSchema"
6  xmlns:isocat="http://www.isocat.org/"
7  xmlns:dcr="http://www.isocat.org/ns/dcr"
8  xmlns:dcif="http://www.isocat.org/ns/dcif"
9  xmlns:atom="http://www.w3.org/2005/Atom"
10>
11
12        <xsl:output method="xml" encoding="utf-8"/>
13
14        <xsl:param name="props"/>
15       
16        <xsl:template match="text()"/>
17       
18        <xsl:function name="isocat:rest">
19                <xsl:param name="node"/>
20                <xsl:value-of select="$props//site"/>
21                <xsl:text>rest/dc/</xsl:text>
22                <xsl:value-of select="$node/(@id|@dc|@ref)"/>
23        </xsl:function>
24
25        <xsl:function name="isocat:link">
26                <xsl:param name="node"/>
27                <span>
28                        <xsl:text>/</xsl:text>
29                        <a href="{isocat:rest($node)}">
30                                <xsl:choose>
31                                        <xsl:when test="exists($node/@identifier)">
32                                                <xsl:value-of select="$node/@identifier"/>
33                                        </xsl:when>
34                                        <xsl:otherwise>
35                                                <xsl:value-of select="isocat:rest($node)"/>
36                                        </xsl:otherwise>
37                                </xsl:choose>
38                        </a>
39                        <xsl:text>/</xsl:text>
40                        <xsl:if test="exists($node/@name) and ($node/@name!=$node/@identifier)">
41                                <xsl:text> (</xsl:text>
42                                <xsl:value-of select="$node/@name"/>
43                                <xsl:text>)</xsl:text>
44                        </xsl:if>
45                </span>
46        </xsl:function>
47
48        <xsl:function name="isocat:title">
49                <xsl:param name="node"/>
50                <xsl:text>History of </xsl:text>
51                <xsl:value-of select="isocat:link($node)"/>
52                <xsl:text> - </xsl:text>
53                <xsl:value-of select="$node/@version"/>
54        </xsl:function>
55       
56        <xsl:function name="isocat:timestamp">
57                <xsl:param name="ts"/>
58                <xsl:sequence select="replace($ts,'\..*','')"/>
59        </xsl:function>
60       
61        <xsl:template match="change">
62                <atom:entry>
63                        <atom:id>
64                                <xsl:value-of select="/history/dc/@pid"/>
65                                <xsl:text>/history#c</xsl:text>
66                                <xsl:value-of select="@isocat:id"/>
67                        </atom:id>
68                        <atom:link rel="alternate" type="text/html">
69                                <xsl:attribute name="href">
70                                        <xsl:value-of select="isocat:rest(/history/dc)"/>
71                                        <xsl:text>/history#c</xsl:text>
72                                        <xsl:value-of select="@isocat:id"/>
73                                </xsl:attribute>
74                        </atom:link>
75                        <atom:title>
76                                <xsl:text>Change by </xsl:text>
77                                <xsl:value-of select="if (normalize-space(user/name)!='') then (user/name) else ('unknown')"/>
78                                <xsl:text> at </xsl:text>
79                                <xsl:value-of select="isocat:timestamp(@timestamp)"/>
80                        </atom:title>
81                        <atom:author>
82                                <atom:name>
83                                        <xsl:value-of select="if (normalize-space(user/name)!='') then (user/name) else ('unknown')"/>
84                                </atom:name>
85                        </atom:author>
86                        <atom:updated>
87                                <xsl:value-of select="isocat:timestamp(@timestamp)"/>
88                        </atom:updated>
89                        <atom:content type="text">
90                                <xsl:value-of select="description"/>
91                        </atom:content>
92                </atom:entry>
93        </xsl:template>
94       
95        <xsl:template match="/history">
96                <xsl:variable name="title" select="isocat:title(dc)"/>
97                <atom:feed>
98                        <atom:id>
99                                <xsl:value-of select="dc/@pid"/>
100                        </atom:id>
101                        <atom:title type="text">
102                                <xsl:value-of select="$title"/>
103                        </atom:title>
104                        <atom:published>
105                                <xsl:value-of select="isocat:timestamp((change)[last()]/@timestamp)"/>
106                        </atom:published>
107                        <xsl:if test="count(change) gt 1">
108                                <atom:updated>
109                                        <xsl:value-of select="isocat:timestamp((change)[1]/@timestamp)"/>
110                                </atom:updated>
111                        </xsl:if>
112                        <atom:link rel="self" type="application/atom+xml">
113                                <xsl:attribute name="href">
114                                        <xsl:value-of select="isocat:rest(dc)"/>
115                                        <xsl:text>/history.atom</xsl:text>
116                                </xsl:attribute>
117                        </atom:link>
118                        <atom:link rel="alternate" type="text/html">
119                                <xsl:attribute name="href">
120                                        <xsl:value-of select="isocat:rest(dc)"/>
121                                        <xsl:text>/history</xsl:text>
122                                </xsl:attribute>
123                        </atom:link>
124                        <xsl:apply-templates select="change">
125                                <xsl:sort order="descending" select="@isocat:id"/>
126                        </xsl:apply-templates>
127                </atom:feed>
128        </xsl:template>
129
130</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.