root/tags/2D14/Resources/default.xsl

Revision 2329, 4.7 kB (checked in by timothy, 4 years ago)

* Added the message type, notice and normal types.
* Adds a type attribute: type="notice"
* No type means a normal message.

Line 
1 <?xml version='1.0' encoding='iso-8859-1'?>
2 <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
3         <xsl:output omit-xml-declaration="yes" indent="no" />
4         <xsl:param name="bulkTransform" />
5         <xsl:param name="timeFormat" />
6
7         <xsl:template match="/">
8                 <xsl:choose>
9                         <xsl:when test="count( /envelope/message ) &gt; 1">
10                                 <xsl:apply-templates select="/envelope/message[last()]" />
11                         </xsl:when>
12                         <xsl:otherwise>
13                                 <xsl:apply-templates />
14                         </xsl:otherwise>
15                 </xsl:choose>
16         </xsl:template>
17
18         <xsl:template match="envelope | message">
19                 <xsl:variable name="envelopeClasses">
20                         <xsl:text>envelope</xsl:text>
21                         <xsl:if test="message[1]/@highlight = 'yes' or @highlight = 'yes'">
22                                 <xsl:text> highlight</xsl:text>
23                         </xsl:if>
24                         <xsl:if test="message[1]/@action = 'yes' or @action = 'yes'">
25                                 <xsl:text> action</xsl:text>
26                         </xsl:if>
27                         <xsl:if test="message[1]/@type = 'notice' or @type = 'notice'">
28                                 <xsl:text> notice</xsl:text>
29                         </xsl:if>
30                         <xsl:if test="message[1]/@ignored = 'yes' or @ignored = 'yes' or ../@ignored = 'yes'">
31                                 <xsl:text> ignore</xsl:text>
32                         </xsl:if>
33                 </xsl:variable>
34
35                 <xsl:variable name="senderClasses">
36                         <xsl:text>member</xsl:text>
37                         <xsl:if test="sender/@self = 'yes' or ../sender/@self = 'yes'">
38                                 <xsl:text> self</xsl:text>
39                         </xsl:if>
40                 </xsl:variable>
41
42                 <xsl:variable name="memberLink">
43                         <xsl:choose>
44                                 <xsl:when test="sender/@identifier or ../sender/@identifier">
45                                         <xsl:text>member:identifier:</xsl:text><xsl:value-of select="sender/@identifier | ../sender/@identifier" />
46                                 </xsl:when>
47                                 <xsl:when test="sender/@nickname or ../sender/@nickname">
48                                         <xsl:text>member:</xsl:text><xsl:value-of select="sender/@nickname | ../sender/@nickname" />
49                                 </xsl:when>
50                                 <xsl:otherwise>
51                                         <xsl:text>member:</xsl:text><xsl:value-of select="sender | ../sender" />
52                                 </xsl:otherwise>
53                         </xsl:choose>
54                 </xsl:variable>
55
56                 <div id="{message[1]/@id | @id}" class="{$envelopeClasses}">
57                         <span class="timestamp hidden">[</span>
58                         <span class="timestamp">
59                                 <xsl:call-template name="short-time">
60                                         <xsl:with-param name="date" select="message[1]/@received | @received" />
61                                 </xsl:call-template>
62                         </span>
63                         <span class="timestamp hidden">] </span>
64                         <a href="{$memberLink}" class="{$senderClasses}"><xsl:value-of select="sender | ../sender" /></a>
65                         <span class="hidden">: </span>
66                         <span class="message">
67                                 <xsl:choose>
68                                         <xsl:when test="message[1]">
69                                                 <xsl:apply-templates select="message[1]/child::node()" mode="copy" />
70                                         </xsl:when>
71                                         <xsl:otherwise>
72                                                 <xsl:apply-templates select="child::node()" mode="copy" />
73                                         </xsl:otherwise>
74                                 </xsl:choose>
75                         </span>
76                 </div>
77
78                 <xsl:apply-templates select="message[position() &gt; 1]" />
79         </xsl:template>
80
81         <xsl:template match="event">
82                 <div class="event">
83                         <span class="timestamp hidden">[</span>
84                         <span class="timestamp">
85                                 <xsl:call-template name="short-time">
86                                         <xsl:with-param name="date" select="@occurred" />
87                                 </xsl:call-template>
88                         </span>
89                         <span class="timestamp hidden">] </span>
90                         <xsl:apply-templates select="message/child::node()" mode="copy" />
91                         <xsl:if test="string-length( reason )">
92                                 <span class="reason">
93                                         <xsl:text> (</xsl:text>
94                                         <xsl:apply-templates select="reason/child::node()" mode="copy"/>
95                                         <xsl:text>)</xsl:text>
96                                 </span>
97                         </xsl:if>
98                 </div>
99         </xsl:template>
100
101         <xsl:template match="span[contains(@class,'member')]" mode="copy">
102                 <a href="member:{current()}" class="member"><xsl:value-of select="current()" /></a>
103         </xsl:template>
104
105         <xsl:template match="@*|*" mode="copy">
106                 <xsl:copy><xsl:apply-templates select="@*|node()" mode="copy" /></xsl:copy>
107         </xsl:template>
108
109         <xsl:template name="short-time">
110                 <xsl:param name="date" /> <!-- YYYY-MM-DD HH:MM:SS +/-HHMM -->
111                 <xsl:variable name='hour' select='substring($date, 12, 2)' />
112                 <xsl:variable name='minute' select='substring($date, 15, 2)' />
113                 <xsl:choose>
114                   <xsl:when test="contains($timeFormat,'H')">
115                     <!-- 24hr format -->
116                     <xsl:value-of select="concat($hour,':',$minute)" />
117                   </xsl:when>
118                   <xsl:otherwise>
119                     <!-- am/pm format -->
120                     <xsl:choose>
121                       <xsl:when test="number($hour) &gt; 12">
122                         <xsl:value-of select="number($hour) - 12" />
123                       </xsl:when>
124                       <xsl:when test="number($hour) = 0">
125                         <xsl:text>12</xsl:text>
126                       </xsl:when>
127                       <xsl:otherwise>
128                         <xsl:value-of select="$hour" />
129                       </xsl:otherwise>
130                     </xsl:choose>
131                     <xsl:text>:</xsl:text>
132                     <xsl:value-of select="$minute" />
133                     <xsl:choose>
134                       <xsl:when test="number($hour) &gt;= 12">
135                         <xsl:text>pm</xsl:text>
136                       </xsl:when>
137                       <xsl:otherwise>
138                         <xsl:text>am</xsl:text>
139                       </xsl:otherwise>
140                     </xsl:choose>
141                   </xsl:otherwise>
142                 </xsl:choose>
143         </xsl:template>
144 </xsl:stylesheet>
Note: See TracBrowser for help on using the browser.