This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsearch_report_xhtml.xsl
268 lines (231 loc) · 8.13 KB
/
search_report_xhtml.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<!--
Copyright 2009 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This code is not supported by Google
****************************************************************************
This XSLT stylesheet is intended to convert XML output from Search Reports
from GSA into human-readable XHTML 1.0 document. You can use any XSTL
processor/software. We recommend using 'xsltproc' command line tool:
$ xsltproc search_report_xhtml.xsl report_search_report_1.xml > output.html
-->
<!-- sort of hashmaps for grouping search report data -->
<xsl:key name="months" match="daily" use="substring(@date,0,8)"/>
<xsl:key name="counts" match="daily" use="@date"/>
<xsl:key name="hourcounts" match="hourlyAvg" use="@hour"/>
<!--
HELPER FUNCTIONS
-->
<!-- for loop in XSL, adapted for search reports -->
<xsl:template name="for.loop">
<xsl:param name="i" />
<xsl:param name="count" />
<xsl:param name="mode" select="'iterate'" />
<xsl:if test="$i <= $count">
<td>
<xsl:if test="$i <= $count">
<xsl:choose>
<xsl:when test="$mode='hour'">
<xsl:value-of select="key('hourcounts', $i)" />
</xsl:when>
<xsl:when test="$mode='iterate'">
<xsl:value-of select="$i" />
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$i < 10">
<xsl:value-of select="key('counts', concat($mode,'-0',$i))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="key('counts', concat($mode,'-',$i))" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</td>
</xsl:if>
<xsl:if test="$i <= $count">
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="$i + 1" />
<xsl:with-param name="count" select="$count" />
<xsl:with-param name="mode" select="$mode" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- returns the name of the month -->
<xsl:template name="format.month">
<xsl:param name="mo" />
<xsl:choose>
<xsl:when test="$mo = '01'"><xsl:value-of select="'January'"/></xsl:when>
<xsl:when test="$mo = '02'"><xsl:value-of select="'February'"/></xsl:when>
<xsl:when test="$mo = '03'"><xsl:value-of select="'March'"/></xsl:when>
<xsl:when test="$mo = '04'"><xsl:value-of select="'April'"/></xsl:when>
<xsl:when test="$mo = '05'"><xsl:value-of select="'May'"/></xsl:when>
<xsl:when test="$mo = '06'"><xsl:value-of select="'June'"/></xsl:when>
<xsl:when test="$mo = '07'"><xsl:value-of select="'July'"/></xsl:when>
<xsl:when test="$mo = '08'"><xsl:value-of select="'August'"/></xsl:when>
<xsl:when test="$mo = '09'"><xsl:value-of select="'September'"/></xsl:when>
<xsl:when test="$mo = '10'"><xsl:value-of select="'October'"/></xsl:when>
<xsl:when test="$mo = '11'"><xsl:value-of select="'November'"/></xsl:when>
<xsl:when test="$mo = '12'"><xsl:value-of select="'December'"/></xsl:when>
</xsl:choose>
</xsl:template>
<!--
MAIN PROCESSING MEAT
-->
<xsl:template match="/">
<xsl:variable name="top" select="summaryReport/reportParams/@topCount" />
<html>
<body>
<h1>Search report - <xsl:value-of select="summaryReport/reportParams/@reportName"/></h1>
<p>Report created on <b><xsl:value-of select="summaryReport/reportParams/@creationDate"/></b>. This report includes the following timeframe: <b><xsl:value-of select="summaryReport/reportParams/@reportDateRange"/></b>. Showing <b><xsl:value-of select="$top"/></b> top entries.</p>
<table border="1">
<tr>
<th>Total result pages</th>
<td><xsl:value-of select="summaryReport/resultPages"/></td>
</tr>
<tr>
<th>Total searches</th>
<td><xsl:value-of select="summaryReport/totalQueries"/></td>
</tr>
<tr>
<th>Distinct searches</th>
<td><xsl:value-of select="summaryReport/distinctQueries"/></td>
</tr>
<tr>
<th>ASR entries</th>
<td><xsl:value-of select="summaryReport/asrEntries"/></td>
</tr>
</table>
<br />
<table border="1">
<tr>
<th>Excluded terms</th>
</tr>
<xsl:for-each select="summaryReport/reportParams/excludedTerm">
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
<h2>Searches per day</h2>
<table border="1">
<!-- loop through months -->
<xsl:for-each select="//daily[generate-id(.)=generate-id(key('months', substring(@date,0,8))[1])]">
<xsl:sort select="substring(@date,0,8)"/>
<!-- loop through days of months -->
<xsl:for-each select="key('months', substring(@date,0,8))">
<xsl:if test="position() = 1">
<tr><th colspan="32">
<xsl:call-template name="format.month">
<xsl:with-param name="mo" select="substring(@date,6,2)" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:value-of select="substring(@date,0,5)"/>
</th></tr>
<tr><th>Date</th>
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="'1'" />
<xsl:with-param name="count" select="'31'" />
</xsl:call-template>
</tr>
</xsl:if>
</xsl:for-each>
<!-- need another loop to create value columns -->
<tr><th>Count</th>
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="'1'" />
<xsl:with-param name="count" select="'31'" />
<xsl:with-param name="mode" select="substring(@date,0,8)" />
</xsl:call-template>
</tr>
<!--<xsl:value-of select="@date"/>-->
</xsl:for-each>
</table>
<h2>Average searches per hour</h2>
<table border="1">
<tr>
<th>Hour</th>
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="'0'" />
<xsl:with-param name="count" select="'23'" />
</xsl:call-template>
</tr>
<tr>
<th>Count</th>
<xsl:call-template name="for.loop">
<xsl:with-param name="i" select="'0'" />
<xsl:with-param name="count" select="'23'" />
<xsl:with-param name="mode" select="'hour'" />
</xsl:call-template>
</tr>
</table>
<h2>Top <xsl:value-of select="$top"/> Keywords</h2>
<table border="1">
<tr>
<th>Term</th>
<th>Occurrence</th>
</tr>
<xsl:for-each select="summaryReport/topKeywords/topKeyword">
<tr>
<td><xsl:value-of select="@keyword"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
<h2>Top <xsl:value-of select="$top"/> Queries</h2>
<table border="1">
<tr>
<th>Query</th>
<th>Occurrence</th>
</tr>
<xsl:for-each select="summaryReport/topQueries/topQuery">
<tr>
<td><xsl:value-of select="@query"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
<h2>ASR IPs</h2>
<table border="1">
<tr>
<th>IP</th>
<th>Occurrence</th>
</tr>
<xsl:for-each select="summaryReport/asrIp/asrIp">
<tr>
<td><xsl:value-of select="@ip"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
<h2>ASR URLs</h2>
<table border="1">
<tr>
<th>URL</th>
<th>Occurrence</th>
</tr>
<xsl:for-each select="summaryReport/asrUrl/asrUrl">
<tr>
<td><xsl:value-of select="@url"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>