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