aboutsummaryrefslogtreecommitdiffstats
path: root/pdml2html.xsl
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2011-05-19 18:10:21 +0000
committerGerald Combs <gerald@wireshark.org>2011-05-19 18:10:21 +0000
commit99d4de66e59c134ba34d61562a03924eddc7df8a (patch)
tree8d090c2b3a5a19f9654b543da753da53d8baa4a4 /pdml2html.xsl
parent375b1bf4b4331f466acafb1b632a72cc90c76d05 (diff)
From Dirk Jagdmann via bug 5875:
My attachment adds a link to a XSLT file to the preamble of the PDML. The XSLT will transform the PDML to a HTML page, and the HTML page features a look similar to Wireshark. See http://cubic.org/~doj/ebay/a.pdml for an example. The patch also contains a small perl program which converts the Wireshark colortable into javascript code which is used in the XSLT file. If you want to use a different color scheme you would execute the perl program and insert the generated javascript function into your XSLT file. To view the HTML you could either place the PDML and XSLT file on your webserver and verify that your webserver sends the PDML file as "text/xml". Then your webbrowser will find the linked XSLT file, download that as well and convert the PDML to HTML on the fly. You could also use an XSLT processor like xsltproc to convert the PDML and XSLT into a static HTML file. From me: Minor fixups. svn path=/trunk/; revision=37298
Diffstat (limited to 'pdml2html.xsl')
-rw-r--r--pdml2html.xsl211
1 files changed, 211 insertions, 0 deletions
diff --git a/pdml2html.xsl b/pdml2html.xsl
new file mode 100644
index 0000000000..4239d7f41f
--- /dev/null
+++ b/pdml2html.xsl
@@ -0,0 +1,211 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<!-- This XSLT will convert a PDML file, saved by Wireshark, into
+ HTML. The HTML page should look like Wireshark. For questions contact
+ Dirk Jagdmann (doj@cubic.org).
+ Version: 2010-06-09 -->
+
+<!-- set parameters of the HTML output -->
+<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="no" standalone="yes" indent="yes"/>
+
+<!-- this matches the "field" tag -->
+<xsl:template match="field">
+ &#160;&#160;&#160; <!-- indent with 3 non-breaking spaces -->
+
+ <!-- output either the "showname" or "show" attribute -->
+ <xsl:choose>
+ <xsl:when test="string-length(@showname)>0">
+ <xsl:value-of select="@showname"/><br/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!--<xsl:value-of select="@name"/>:--> <xsl:value-of select="@show"/><br/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:apply-templates/> <!-- we expect to match "field" tags -->
+</xsl:template>
+
+<!-- this matches the "packet" tag -->
+<xsl:template match="packet">
+
+ <!-- declare some variables for later use -->
+ <xsl:variable name="frame_num" select="proto[@name='frame']/field[@name='frame.number']/@show"/>
+ <xsl:variable name="frame_id" select="concat('f',$frame_num)"/>
+ <xsl:variable name="frame_c" select="concat($frame_id,'c')"/>
+
+ <!-- the "title" bar of the frame -->
+ <div width="100%" id="{$frame_id}">
+ <a href="javascript:toggle_node('{$frame_c}')">&#8658;</a> <!-- #8658 is a "rArr" (double right arrow) character -->
+ Frame <xsl:value-of select="$frame_num"/>:
+ <xsl:for-each select="proto[@name!='geninfo']">
+ <xsl:value-of select="@name"/>,
+ </xsl:for-each>
+ <small><a href="javascript:hide_node('{$frame_id}')">[X]</a></small>
+ </div>
+
+ <!-- the frame contents are stored in a div, so we can toggle it -->
+ <div width="100%" id="{$frame_c}" style="display:none">
+ <!-- loop trough all proto tags, but skip the "geninfo" one -->
+ <xsl:for-each select="proto[@name!='geninfo']">
+
+ <xsl:variable name="proto" select="concat($frame_id,@name)"/>
+
+ <!-- the "title" bar of the proto -->
+ <div width="100%" style="background-color:#e5e5e5; margin-bottom: 2px">
+ &#160;<a href="javascript:toggle_node('{$proto}')">&#8658;</a>&#160;<xsl:value-of select="@showname"/>
+
+ <!-- print "proto" details inside another div -->
+ <div width="100%" id="{$proto}" style="display:none">
+ <xsl:apply-templates/> <!-- we expect to match "field" tags -->
+ </div>
+ </div>
+ </xsl:for-each>
+ </div>
+
+ <!-- use the javascript function set_node_color() to set the color
+ of the frame title bar. Defer colorization until the full page has
+ been loaded. If the browser would support the XPath function
+ replace() we could simply set the class attribute of the title bar div,
+ but for now we're stuck with class names from Wireshark's colorfilters
+ that contain spaces and we can't handle them in CSS. -->
+ <script type="text/javascript">
+ dojo.addOnLoad(function(){
+ set_node_color(
+ '<xsl:value-of select="$frame_id"/>',
+ '<xsl:value-of select="proto[@name='frame']/field[@name='frame.coloring_rule.name']/@show"/>'
+ );
+ });
+ </script>
+</xsl:template>
+
+<xsl:template match="pdml">
+ Capture Filename: <b><xsl:value-of select="@capture_file"/></b>
+ PDML created: <b><xsl:value-of select="@time"/></b>
+ <tt>
+ <xsl:apply-templates/> <!-- we expect to match the "packet" nodes -->
+ </tt>
+</xsl:template>
+
+<!-- this block matches the start of the PDML file -->
+<xsl:template match="/">
+ <html>
+ <head>
+ <title>poor man's Wireshark</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" type="text/javascript"></script>
+ <script type="text/javascript">
+function set_node(node, str)
+{
+ if(dojo.isString(node))
+ node = dojo.byId(node);
+ if(!node) return;
+ node.style.display = str;
+}
+function toggle_node(node)
+{
+ if(dojo.isString(node))
+ node = dojo.byId(node);
+ if(!node) return;
+ set_node(node, (node.style.display != 'none') ? 'none' : 'block');
+}
+function hide_node(node)
+{
+ set_node(node, 'none');
+}
+// this function was generated by colorfilters2js.pl
+function set_node_color(node,colorname)
+{
+ if(dojo.isString(node))
+ node = dojo.byId(node);
+ if(!node) return;
+ var fg;
+ var bg;
+ if(colorname == 'Bad TCP') {
+ bg='#000000';
+ fg='#ff5f5f';
+ }
+ if(colorname == 'HSRP State Change') {
+ bg='#000000';
+ fg='#fff600';
+ }
+ if(colorname == 'Spanning Tree Topology Change') {
+ bg='#000000';
+ fg='#fff600';
+ }
+ if(colorname == 'OSPF State Change') {
+ bg='#000000';
+ fg='#fff600';
+ }
+ if(colorname == 'ICMP errors') {
+ bg='#000000';
+ fg='#00ff0e';
+ }
+ if(colorname == 'ARP') {
+ bg='#d6e8ff';
+ fg='#000000';
+ }
+ if(colorname == 'ICMP') {
+ bg='#c2c2ff';
+ fg='#000000';
+ }
+ if(colorname == 'TCP RST') {
+ bg='#900000';
+ fg='#fff680';
+ }
+ if(colorname == 'TTL low or unexpected') {
+ bg='#900000';
+ fg='#ffffff';
+ }
+ if(colorname == 'Checksum Errors') {
+ bg='#000000';
+ fg='#ff5f5f';
+ }
+ if(colorname == 'SMB') {
+ bg='#fffa99';
+ fg='#000000';
+ }
+ if(colorname == 'HTTP') {
+ bg='#8dff7f';
+ fg='#000000';
+ }
+ if(colorname == 'IPX') {
+ bg='#ffe3e5';
+ fg='#000000';
+ }
+ if(colorname == 'DCERPC') {
+ bg='#c797ff';
+ fg='#000000';
+ }
+ if(colorname == 'Routing') {
+ bg='#fff3d6';
+ fg='#000000';
+ }
+ if(colorname == 'TCP SYN/FIN') {
+ bg='#a0a0a0';
+ fg='#000000';
+ }
+ if(colorname == 'TCP') {
+ bg='#e7e6ff';
+ fg='#000000';
+ }
+ if(colorname == 'UDP') {
+ bg='#70e0ff';
+ fg='#000000';
+ }
+ if(colorname == 'Broadcast') {
+ bg='#ffffff';
+ fg='#808080';
+ }
+ if(fg.length > 0)
+ node.style.color = fg;
+ if(bg.length > 0)
+ node.style.background = bg;
+}
+ </script>
+ </head>
+ <body>
+ <xsl:apply-templates/> <!-- we expect to match the "pdml" node -->
+ </body>
+ </html>
+</xsl:template>
+
+</xsl:stylesheet>