Merge with the FreeRADIUS version.
[metze/wireshark/wip.git] / pdml2html.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <!-- This XSLT will convert a PDML file, saved by Wireshark, into
4      HTML. The HTML page should look similar to Wireshark. See
5      https://wiki.wireshark.org/PDML how to generate such a HTML file from PDML.
6      For questions contact Dirk Jagdmann (doj@cubic.org).
7
8      Version: 2010-06-09
9
10      Wireshark - Network traffic analyzer
11      By Gerald Combs <gerald@wireshark.org>
12      Copyright 1998 Gerald Combs
13
14      This program is free software; you can redistribute it and/or
15      modify it under the terms of the GNU General Public License
16      as published by the Free Software Foundation; either version 2
17      of the License, or (at your option) any later version.
18
19      This program is distributed in the hope that it will be useful,
20      but WITHOUT ANY WARRANTY; without even the implied warranty of
21      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22      GNU General Public License for more details.
23
24      You should have received a copy of the GNU General Public License
25      along with this program; if not, write to the Free Software
26      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27      -->
28
29 <!-- set parameters of the HTML output -->
30 <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="no" standalone="yes" indent="yes"/>
31
32 <!-- this matches the "field" tag -->
33 <xsl:template match="field">
34   &#160;&#160;&#160; <!-- indent with 3 non-breaking spaces -->
35
36   <!-- output either the "showname" or "show" attribute -->
37   <xsl:choose>
38     <xsl:when test="string-length(@showname)>0">
39       <xsl:value-of select="@showname"/><br/>
40     </xsl:when>
41     <xsl:otherwise>
42       <!--<xsl:value-of select="@name"/>:--> <xsl:value-of select="@show"/><br/>
43     </xsl:otherwise>
44   </xsl:choose>
45
46   <xsl:apply-templates/> <!-- we expect to match "field" tags -->
47 </xsl:template>
48
49 <!-- this matches the "packet" tag -->
50 <xsl:template match="packet">
51
52   <!-- declare some variables for later use -->
53   <xsl:variable name="frame_num" select="proto[@name='frame']/field[@name='frame.number']/@show"/>
54   <xsl:variable name="frame_id"  select="concat('f',$frame_num)"/>
55   <xsl:variable name="frame_c"   select="concat($frame_id,'c')"/>
56
57   <!-- the "title" bar of the frame -->
58   <div width="100%" id="{$frame_id}">
59     <a href="javascript:toggle_node('{$frame_c}')">&#8658;</a> <!-- #8658 is a "rArr" (double right arrow) character -->
60     Frame <xsl:value-of select="$frame_num"/>:
61     <xsl:for-each select="proto[@name!='geninfo']">
62       <xsl:value-of select="@name"/>,
63     </xsl:for-each>
64     <small><a href="javascript:hide_node('{$frame_id}')">[X]</a></small>
65   </div>
66
67   <!-- the frame contents are stored in a div, so we can toggle it -->
68   <div width="100%" id="{$frame_c}" style="display:none">
69     <!-- loop through all proto tags, but skip the "geninfo" one -->
70     <xsl:for-each select="proto[@name!='geninfo']">
71
72       <xsl:variable name="proto" select="concat($frame_id,@name,count(preceding-sibling::proto)+1)"/>
73
74       <!-- the "title" bar of the proto -->
75       <div width="100%" style="background-color:#e5e5e5; margin-bottom: 2px">
76         &#160;<a href="javascript:toggle_node('{$proto}')">&#8658;</a>&#160;<xsl:value-of select="@showname"/>
77
78         <!-- print "proto" details inside another div -->
79         <div width="100%" id="{$proto}" style="display:none">
80          <xsl:apply-templates/> <!-- we expect to match "field" tags -->
81         </div>
82       </div>
83     </xsl:for-each>
84   </div>
85
86   <!-- use the javascript function set_node_color() to set the color
87        of the frame title bar. Defer colorization until the full page has
88        been loaded. If the browser would support the XPath function
89        replace() we could simply set the class attribute of the title bar div,
90        but for now we're stuck with class names from Wireshark's colorfilters
91        that contain spaces and we can't handle them in CSS. -->
92   <script type="text/javascript">
93     dojo.addOnLoad(function(){
94       set_node_color(
95         '<xsl:value-of select="$frame_id"/>',
96         '<xsl:value-of select="proto[@name='frame']/field[@name='frame.coloring_rule.name']/@show"/>'
97       );
98     });
99   </script>
100 </xsl:template>
101
102 <xsl:template match="pdml">
103   Capture Filename: <b><xsl:value-of select="@capture_file"/></b>
104   PDML created: <b><xsl:value-of select="@time"/></b>
105   <tt>
106     <xsl:apply-templates/> <!-- we expect to match the "packet" nodes -->
107   </tt>
108 </xsl:template>
109
110 <!-- this block matches the start of the PDML file -->
111 <xsl:template match="/">
112   <html>
113   <head>
114     <title>poor man's Wireshark</title>
115     <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" type="text/javascript"></script>
116     <script type="text/javascript">
117 function set_node(node, str)
118 {
119   if(dojo.isString(node))
120     node = dojo.byId(node);
121   if(!node) return;
122   node.style.display = str;
123 }
124 function toggle_node(node)
125 {
126   if(dojo.isString(node))
127     node = dojo.byId(node);
128   if(!node) return;
129   set_node(node, (node.style.display != 'none') ? 'none' : 'block');
130 }
131 function hide_node(node)
132 {
133   set_node(node, 'none');
134 }
135 // this function was generated by colorfilters2js.pl
136 function set_node_color(node,colorname)
137 {
138   if(dojo.isString(node))
139     node = dojo.byId(node);
140   if(!node) return;
141   var fg;
142   var bg;
143   if(colorname == 'Bad TCP') {
144     bg='#000000';
145     fg='#ff5f5f';
146   }
147   if(colorname == 'HSRP State Change') {
148     bg='#000000';
149     fg='#fff600';
150   }
151   if(colorname == 'Spanning Tree Topology  Change') {
152     bg='#000000';
153     fg='#fff600';
154   }
155   if(colorname == 'OSPF State Change') {
156     bg='#000000';
157     fg='#fff600';
158   }
159   if(colorname == 'ICMP errors') {
160     bg='#000000';
161     fg='#00ff0e';
162   }
163   if(colorname == 'ARP') {
164     bg='#d6e8ff';
165     fg='#000000';
166   }
167   if(colorname == 'ICMP') {
168     bg='#c2c2ff';
169     fg='#000000';
170   }
171   if(colorname == 'TCP RST') {
172     bg='#900000';
173     fg='#fff680';
174   }
175   if(colorname == 'TTL low or unexpected') {
176     bg='#900000';
177     fg='#ffffff';
178   }
179   if(colorname == 'Checksum Errors') {
180     bg='#000000';
181     fg='#ff5f5f';
182   }
183   if(colorname == 'SMB') {
184     bg='#fffa99';
185     fg='#000000';
186   }
187   if(colorname == 'HTTP') {
188     bg='#8dff7f';
189     fg='#000000';
190   }
191   if(colorname == 'IPX') {
192     bg='#ffe3e5';
193     fg='#000000';
194   }
195   if(colorname == 'DCERPC') {
196     bg='#c797ff';
197     fg='#000000';
198   }
199   if(colorname == 'Routing') {
200     bg='#fff3d6';
201     fg='#000000';
202   }
203   if(colorname == 'TCP SYN/FIN') {
204     bg='#a0a0a0';
205     fg='#000000';
206   }
207   if(colorname == 'TCP') {
208     bg='#e7e6ff';
209     fg='#000000';
210   }
211   if(colorname == 'UDP') {
212     bg='#70e0ff';
213     fg='#000000';
214   }
215   if(colorname == 'Broadcast') {
216     bg='#ffffff';
217     fg='#808080';
218   }
219   if(fg.length > 0)
220     node.style.color = fg;
221   if(bg.length > 0)
222     node.style.background = bg;
223 }
224     </script>
225   </head>
226     <body>
227       <xsl:apply-templates/> <!-- we expect to match the "pdml" node -->
228     </body>
229   </html>
230 </xsl:template>
231
232 </xsl:stylesheet>