summaryrefslogtreecommitdiff
path: root/data/log-manager.xsl
blob: b81fb1896eda7dfc0d1e21312135a8735864938e (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!--
This XSL stylesheet generates readable HTML output from an Empathy-style XML
log file.

To generate a HTML file, try something like:

    xsltproc \-\-stringparam title "Chat Log" log-manager.xsl logfile.log
-->

<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

  <xsl:output method="html" encoding="utf-8" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <style type="text/css">
          <xsl:text>
            body {
              background: #fff;
	      font-family: Verdana, "Bitstream Vera Sans", Sans-Serif;
	      font-size: 10pt;
            }
            .stamp {
              color: #999;
            }
            .top-day-stamp {
              color: #999;
              text-align: center;
              margin-bottom: 1em;
            }
            .new-day-stamp {
              color: #999;
              text-align: center;
              margin-bottom: 1em;
              margin-top: 1em;
            }
            .nick {
              color: rgb(54,100, 139);
            }
            .nick-self {
              color: rgb(46,139,87);
            }
           .nick-highlight {
              color: rgb(205,92,92);
            }
          </xsl:text>
        </style>
        <title><xsl:value-of select="$title"/></title>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="get-day">
    <xsl:param name="stamp"/>
    <xsl:value-of select="substring ($stamp, 1, 8)"/>
  </xsl:template>

  <xsl:template name="format-stamp">
    <xsl:param name="stamp"/>
    <xsl:variable name="hour" select="substring ($stamp, 10, 2)"/>
    <xsl:variable name="min" select="substring ($stamp, 13, 2)"/>

    <xsl:value-of select="$hour"/>:<xsl:value-of select="$min"/>
  </xsl:template>

  <xsl:template name="format-day-stamp">
    <xsl:param name="stamp"/>
    <xsl:variable name="year" select="substring ($stamp, 1, 4)"/>
    <xsl:variable name="month" select="substring ($stamp, 5, 2)"/>
    <xsl:variable name="day" select="substring ($stamp, 7, 2)"/>

    <xsl:value-of select="$year"/>-<xsl:value-of select="$month"/>-<xsl:value-of select="$day"/>
  </xsl:template>

  <xsl:template name="header">
    <xsl:param name="stamp"/>
    <div class="top-day-stamp">
      <xsl:call-template name="format-day-stamp">
        <xsl:with-param name="stamp" select="@time"/>
      </xsl:call-template>
    </div>
  </xsl:template>

  <xsl:template match="a">
    <xsl:text disable-output-escaping="yes">&lt;a href="</xsl:text>

    <xsl:value-of disable-output-escaping="yes" select="@href"/>

    <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>

    <xsl:value-of select="@href"/>
    <xsl:text disable-output-escaping="yes">&lt;/a&gt;</xsl:text>
  </xsl:template>

  <xsl:template match="log">

    <div class="top-day-stamp">
      <xsl:call-template name="format-day-stamp">
        <xsl:with-param name="stamp" select="//message[1]/@time"/>
      </xsl:call-template>
    </div>

    <xsl:for-each select="*">

      <xsl:variable name="prev-time">
        <xsl:call-template name="get-day">
          <xsl:with-param name="stamp" select="preceding-sibling::*[1]/@time"/>
        </xsl:call-template>
      </xsl:variable>

      <xsl:variable name="this-time">
        <xsl:call-template name="get-day">
          <xsl:with-param name="stamp" select="@time"/>
        </xsl:call-template>
      </xsl:variable>

      <xsl:if test="$prev-time &lt; $this-time">
        <div class="new-day-stamp">
        <xsl:call-template name="format-day-stamp">
          <xsl:with-param name="stamp" select="@time"/>
        </xsl:call-template>
        </div>
      </xsl:if>

      <xsl:variable name="stamp">
        <xsl:call-template name="format-stamp">
          <xsl:with-param name="stamp" select="@time"/>
        </xsl:call-template>
      </xsl:variable>

      <span class="stamp">
       <xsl:value-of select="$stamp"/>
      </span>

      <xsl:variable name="nick-class">
        <xsl:choose>
          <xsl:when test="not(string(@id))">nick-self</xsl:when>
          <xsl:otherwise>nick</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <span class="{$nick-class}">
        &lt;<xsl:value-of select="@name"/>&gt;
      </span>

      <xsl:apply-templates/>
      <br/>

    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>