- 论坛徽章:
- 0
|
为什么我把html文件放在linux环境的apache下面,我通过IE浏览有错误,不能显示.这个html放在window下面,用IE浏览是好的.这个html用到了xml和xsl.
//test-IndexView.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">;
<head>;
<link rel="stylesheet" type="text/css" href="capture-css.css"/>;
<script src="LoadXML.js">;</script>;
</head>;
<body>;
<div id="IDOutputHTML" />;
<script>;
// Update the tree and dump frames
function RefreshViews(Number)
{
// shows and sorts selected packet
window.parent.frames[0].LightPacket(Number);
// shows the tree view
window.parent.frames[1].LoadPacketTree(Number);
// shows the dump view
window.parent.frames[2].LoadPacketDump(Number,1,0);
}
function LightPacket(Number)
{
//DisplayTransformedXML(Number, "test-psml.xml", "XslIndex.xsl" ;
DisplayTransformedXML(Number, "0624-s.xml", "XslIndex.xsl" ;
}
LightPacket(1);
</script>;
</body>;
</html>;
///////LoadXML.js
function DisplayTransformedXML(Number, XMLFile, XSLFile)
{
BrowserName = navigator.appName;
Version = navigator.appVersion; // Version is not used in the following code
if (BrowserName == "Netscape"
{
var XMLHTTPRequest;
var XSLStyleSheet;
var XSLProcessor;
var XMLSource;
// Load the XML source file
XMLHTTPRequest = new XMLHttpRequest();
XMLHTTPRequest.open("GET", XMLFile, false);
XMLHTTPRequest.send(null);
XMLSource = XMLHTTPRequest.responseXML;
// Load the XSL style sheet
XMLHTTPRequest = new XMLHttpRequest();
XMLHTTPRequest.open("GET", XSLFile, false);
XMLHTTPRequest.send(null);
XSLStyleSheet = XMLHTTPRequest.responseXML;
// Instantiate the XSLT processor and associate a XSL style sheet with it
XSLProcessor= new XSLTProcessor();
XSLProcessor.importStylesheet(XSLStyleSheet);
/* Code needed to debug some XML object in Mozilla */
// var Serializer= new XMLSerializer();
// window.alert( Serializer.serializeToString( xslStylesheet ) );
/* End code needed to debug some XML object in Mozilla */
// Set an optional parameter to the style sheet
XSLProcessor.setParameter(null, "selected_packet", Number);
// Transform the XML source according to the appropriate style sheet
var XMLDOMFragment = XSLProcessor.transformToFragment(XMLSource, document);
document.getElementById("IDOutputHTML" .innerHTML = "";
// Print the result of the transformation into the appropriate element into the HTML page
document.getElementById("IDOutputHTML" .appendChild(XMLDOMFragment);
}
else if (BrowserName == "Microsoft Internet Explorer"
{
var XSLStyleSheet;
var XMLSource;
var XSLTemplate;
var XSLProcessor;
// Load the XML source file
XMLSource = new ActiveXObject("Msxml2.DOMDocument" ;
XMLSource.async = false;
XMLSource.resolveExternals = false;
XMLSource.load(XMLFile);
// Load the XSL style sheet
var XSLStyleSheet= new ActiveXObject("Msxml2.FreeThreadedDOMDocument" ;
XSLStyleSheet.load(XSLFile);
// We cannot use the following lines, because templates must be created as 'FreeThreadedDOMDocument'
// In case we do not want to set parameters to the style sheet, we can use the code below and skip the rest
// XSLStyleSheet= document.getElementById("IDStyleSheet" ;
// XSLStyleSheet.async = false;
// XSLStyleSheet.resolveExternals = false;
// IDOutputHTML.innerHTML= source.transformNode(XSLStyleSheet); // This line works only in IE; the next one is equivalent and it works also in Mozilla
// document.getElementById("IDOutputHTML" .innerHTML= XMLSource.transformNode(XSLStyleSheet);
XSLStyleSheet.async = false;
XSLStyleSheet.resolveExternals = false;
// Instantiate the XSLT processor and associate a XSL style sheet with it
XSLTemplate= new ActiveXObject("Msxml2.XSLTemplate");
XSLTemplate.stylesheet= XSLStyleSheet;
XSLProcessor= XSLTemplate.createProcessor();
XSLProcessor.input = XMLSource;
// Set an optional parameter to the style sheet
XSLProcessor.addParameter("selected_packet", Number);
// Transform the XML source according to the appropriate style sheet
XSLProcessor.transform();
// Print the result of the transformation into the appropriate element into the HTML page
document.getElementById("IDOutputHTML").innerHTML= XSLProcessor.output;
}
}
///////capture-css.css
body,tbody
{
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
white-space: nowrap;
}
table
{
border-collapse: collapse;
}
th
{
font-size: 0.7em;
text-align: left;
vertical-align: top;
background-color: silver;
}
td
{
font-size: 0.7em;
text-align: left;
vertical-align: top;
}
pre
{
/* this is a bit big because otherwise Mozilla displays it rather small */
font-size: 1.2em;
}
/* Formatting for the summary view */
.IndexSelected {background-color:lime; }
/* Formatting for the tree view */
.directory p { font-size: 0.7em; margin: 0px; white-space: nowrap; }
.directory img { vertical-align: middle; }
.directory div { display: none; margin: 0px; }
.TreeProto { /*font-weight:bold;*/ }
.TreeField { }
/* Formatting for the dump view */
.DumpSelected {color:red; font-weight:bold;}
.DumpNormal {color:black }
.DumpTest {color:#eeeeee }
/////XslIndex.xsl
<?xml version="1.0" encoding="UTF-8"?>;
<xsl:stylesheet version="1.0" xmlns sl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">;
<xsl utput method="html" omit-xml-declaration="no" indent="yes"/>;
<xsl:param name="selected_packet" select="'1'"/>;
<!-- This stylesheet does not work when the capture was generated after copying/cutting elements, because -->;
<!-- the value in the PSML file does not match the position in the PDML file. -->;
<xsl:template match="/">;
<html>;
<head>;
<link rel="stylesheet" type="text/css" href="capture-css.css"/>;
</head>;
<body>;
<table border="1">;
<xsl:apply-templates/>;
</table>;
</body>;
</html>;
</xsl:template>;
<xsl:template match="structure">;
<tr>;
<xsl:for-each select="section">;
<th>;
<xsl:value-of select="." />;
</th>;
</xsl:for-each>;
</tr>;
</xsl:template>;
<xsl:template match="packet">;
<!-- Save the position of the current packet into the 'num' variable -->;
<xsl:variable name="num" select="section" />;
<xsl:choose>;
<xsl:when test="section= $selected_packet">;
<tr class="IndexSelected">;
<xsl:for-each select="section">;
<td>;
<xsl:if test="position()=1">;
<img src="pktindex.png"/>;
</xsl:if>;
<xsl:value-of select="."/>;
</td>;
</xsl:for-each>;
</tr>;
</xsl:when>;
<xsl therwise>;
<tr onClick="RefreshViews({$num})">;
<xsl:for-each select="section">;
<td>;
<!--
This code should print a 'no break space' in all the cells
However, it does not work in IE6, while it works perfectly well in Xalan.
No idea why
-->;
<!--
<xsl:text disable-output-escaping="yes">;&nbps;</xsl:text>;
-->;
<xsl:if test="position()=1">;
<img src="pktindex.png"/>;
</xsl:if>;
<xsl:value-of select="."/>;
</td>;
</xsl:for-each>;
</tr>;
</xsl therwise>;
</xsl:choose>;
</xsl:template>;
</xsl:stylesheet>;
test-psml.xml如下:
<?xml version="1.0" encoding="utf-8" ?>;
<psml version="0" creator="NetBee Packet Decoding Engine" dissectors="04-jan-2004">;
<structure>;
<section>;N.</section>;
<section>;Time</section>;
<section>;Data Link</section>;
<section>;Network</section>;
<section>;Transport</section>;
<section>;Application</section>;
</structure>;
<packet>;
<section>;1</section>;
<section>;22:04:01.207911</section>;
<section>;Eth: 000B5D-20CD02 =>; FFFFFF-FFFFFF</section>;
<section>;IP: 0.0.0.0 =>; 255.255.255.255 (Len 351)</section>;
<section>;UDP: Port 68 =>; 67</section>;
<section>;DHCP Request: Transaction ID 3462696297 DHCP Request</section>;
</packet>;
<packet>;
<section>;2</section>;
<section>;22:04:01.215198</section>;
<section>;Eth: 00095B-2D759A =>; FFFFFF-FFFFFF</section>;
<section>;ARP Request: who has 192.168.0.2 tell 192.168.0.1</section>;
<section>;</section>;
<section>;Data</section>;
</packet>;
<packet>;
<section>;3</section>;
<section>;22:04:01.332685</section>;
<section>;Eth: 00095B-2D759A =>; FFFFFF-FFFFFF</section>;
<section>;IP: 192.168.0.1 =>; 255.255.255.255 (Len 576)</section>;
<section>;UDP: Port 67 =>; 68</section>;
<section>;DHCP Reply: Transaction ID 3462696297 DHCP Acknowledgement</section>;
</packet>;
<packet>;
<section>;4</section>;
<section>;22:04:01.337146</section>;
<section>;Eth: 000B5D-20CD02 =>; FFFFFF-FFFFFF</section>;
<section>;ARP Request: who has 192.168.0.2 tell 192.168.0.2</section>;
<section>;</section>;
<section>;</section>;
</packet>;
</psml>; |
|