Conform indentation to that specified by the modeline; Reformat long lines.
[obnox/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 like Wireshark. For questions contact
5      Dirk Jagdmann (doj@cubic.org).
6      Version: 2010-06-09 -->
7
8 <!-- set parameters of the HTML output -->
9 <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="no" standalone="yes" indent="yes"/>
10
11 <!-- this matches the "field" tag -->
12 <xsl:template match="field">
13   &#160;&#160;&#160; <!-- indent with 3 non-breaking spaces -->
14
15   <!-- output either the "showname" or "show" attribute -->
16   <xsl:choose>
17     <xsl:when test="string-length(@showname)>0">
18       <xsl:value-of select="@showname"/><br/>
19     </xsl:when>
20     <xsl:otherwise>
21       <!--<xsl:value-of select="@name"/>:--> <xsl:value-of select="@show"/><br/>
22     </xsl:otherwise>
23   </xsl:choose>
24
25   <xsl:apply-templates/> <!-- we expect to match "field" tags -->
26 </xsl:template>
27
28 <!-- this matches the "packet" tag -->
29 <xsl:template match="packet">
30
31   <!-- declare some variables for later use -->
32   <xsl:variable name="frame_num" select="proto[@name='frame']/field[@name='frame.number']/@show"/>
33   <xsl:variable name="frame_id"  select="concat('f',$frame_num)"/>
34   <xsl:variable name="frame_c"   select="concat($frame_id,'c')"/>
35
36   <!-- the "title" bar of the frame -->
37   <div width="100%" id="{$frame_id}">
38     <a href="javascript:toggle_node('{$frame_c}')">&#8658;</a> <!-- #8658 is a "rArr" (double right arrow) character -->
39     Frame <xsl:value-of select="$frame_num"/>:
40     <xsl:for-each select="proto[@name!='geninfo']">
41       <xsl:value-of select="@name"/>,
42     </xsl:for-each>
43     <small><a href="javascript:hide_node('{$frame_id}')">[X]</a></small>
44   </div>
45
46   <!-- the frame contents are stored in a div, so we can toggle it -->
47   <div width="100%" id="{$frame_c}" style="display:none">
48     <!-- loop trough all proto tags, but skip the "geninfo" one -->
49     <xsl:for-each select="proto[@name!='geninfo']">
50
51       <xsl:variable name="proto" select="concat($frame_id,@name)"/>
52
53       <!-- the "title" bar of the proto -->
54       <div width="100%" style="background-color:#e5e5e5; margin-bottom: 2px">
55         &#160;<a href="javascript:toggle_node('{$proto}')">&#8658;</a>&#160;<xsl:value-of select="@showname"/>
56
57         <!-- print "proto" details inside another div -->
58         <div width="100%" id="{$proto}" style="display:none">
59          <xsl:apply-templates/> <!-- we expect to match "field" tags -->
60         </div>
61       </div>
62     </xsl:for-each>
63   </div>
64
65   <!-- use the javascript function set_node_color() to set the color
66        of the frame title bar. Defer colorization until the full page has
67        been loaded. If the browser would support the XPath function
68        replace() we could simply set the class attribute of the title bar div,
69        but for now we're stuck with class names from Wireshark's colorfilters
70        that contain spaces and we can't handle them in CSS. -->
71   <script type="text/javascript">
72     dojo.addOnLoad(function(){
73       set_node_color(
74         '<xsl:value-of select="$frame_id"/>',
75         '<xsl:value-of select="proto[@name='frame']/field[@name='frame.coloring_rule.name']/@show"/>'
76       );
77     });
78   </script>
79 </xsl:template>
80
81 <xsl:template match="pdml">
82   Capture Filename: <b><xsl:value-of select="@capture_file"/></b>
83   PDML created: <b><xsl:value-of select="@time"/></b>
84   <tt>
85     <xsl:apply-templates/> <!-- we expect to match the "packet" nodes -->
86   </tt>
87 </xsl:template>
88
89 <!-- this block matches the start of the PDML file -->
90 <xsl:template match="/">
91   <html>
92   <head>
93     <title>poor man's Wireshark</title>
94     <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" type="text/javascript"></script>
95     <script type="text/javascript">
96 function set_node(node, str)
97 {
98   if(dojo.isString(node))
99     node = dojo.byId(node);
100   if(!node) return;
101   node.style.display = str;
102 }
103 function toggle_node(node)
104 {
105   if(dojo.isString(node))
106     node = dojo.byId(node);
107   if(!node) return;
108   set_node(node, (node.style.display != 'none') ? 'none' : 'block');
109 }
110 function hide_node(node)
111 {
112   set_node(node, 'none');
113 }
114 // this function was generated by colorfilters2js.pl
115 function set_node_color(node,colorname)
116 {
117   if(dojo.isString(node))
118     node = dojo.byId(node);
119   if(!node) return;
120   var fg;
121   var bg;
122   if(colorname == 'Bad TCP') {
123     bg='#000000';
124     fg='#ff5f5f';
125   }
126   if(colorname == 'HSRP State Change') {
127     bg='#000000';
128     fg='#fff600';
129   }
130   if(colorname == 'Spanning Tree Topology  Change') {
131     bg='#000000';
132     fg='#fff600';
133   }
134   if(colorname == 'OSPF State Change') {
135     bg='#000000';
136     fg='#fff600';
137   }
138   if(colorname == 'ICMP errors') {
139     bg='#000000';
140     fg='#00ff0e';
141   }
142   if(colorname == 'ARP') {
143     bg='#d6e8ff';
144     fg='#000000';
145   }
146   if(colorname == 'ICMP') {
147     bg='#c2c2ff';
148     fg='#000000';
149   }
150   if(colorname == 'TCP RST') {
151     bg='#900000';
152     fg='#fff680';
153   }
154   if(colorname == 'TTL low or unexpected') {
155     bg='#900000';
156     fg='#ffffff';
157   }
158   if(colorname == 'Checksum Errors') {
159     bg='#000000';
160     fg='#ff5f5f';
161   }
162   if(colorname == 'SMB') {
163     bg='#fffa99';
164     fg='#000000';
165   }
166   if(colorname == 'HTTP') {
167     bg='#8dff7f';
168     fg='#000000';
169   }
170   if(colorname == 'IPX') {
171     bg='#ffe3e5';
172     fg='#000000';
173   }
174   if(colorname == 'DCERPC') {
175     bg='#c797ff';
176     fg='#000000';
177   }
178   if(colorname == 'Routing') {
179     bg='#fff3d6';
180     fg='#000000';
181   }
182   if(colorname == 'TCP SYN/FIN') {
183     bg='#a0a0a0';
184     fg='#000000';
185   }
186   if(colorname == 'TCP') {
187     bg='#e7e6ff';
188     fg='#000000';
189   }
190   if(colorname == 'UDP') {
191     bg='#70e0ff';
192     fg='#000000';
193   }
194   if(colorname == 'Broadcast') {
195     bg='#ffffff';
196     fg='#808080';
197   }
198   if(fg.length > 0)
199     node.style.color = fg;
200   if(bg.length > 0)
201     node.style.background = bg;
202 }
203     </script>
204   </head>
205     <body>
206       <xsl:apply-templates/> <!-- we expect to match the "pdml" node -->
207     </body>
208   </html>
209 </xsl:template>
210
211 </xsl:stylesheet>