| Newsgroups |
gmane.comp.mozilla.devel.layout.xslt |
| Organization |
http://groups.google.com |
| Message-ID |
<[email protected]> |
I'm having issues with my javascript to display some xsl/xml. here's
is the script:
<script type="text/javascript">
var isIE;
var isOpera;
var isNav;
isIE = (navigator.appName == "Microsoft Internet Explorer");
isNav = (navigator.appName == "Netscape");
isOpera = (navigator.appName == "Opera");
if (isIE)
{
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("statsreport.xml")
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("nodestats.xsl")
// Transform
document.write(xml.transformNode(xsl))
}
if (isNav)
{
//for mozilla/netscape
var processor = new XSLTProcessor();
var xslt = document.implementation.createDocument("", "", null);
xslt.load("nodestats.xsl");
processor.importStylesheet(xslt);
var src_doc = document.implementation.createDocument("","", null);
src_doc.load("statsreport.xml");
var result = processor.transformToDocument(src_doc);
}
</script>
Here is the xsl:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www/w3.org/1999/XSL/Transform">
<!-- Root template -->
<xsl:template match="/">
<html>
<head>
<title>Node Statistics</title>
<link href="StatsReport.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<xsl:apply-templates select="StatsReport"/>
</body>
</html>
</xsl:template>
<!-- StatsReport template -->
<xsl:template match="StatsReport"><xsl:apply-templates
select="NodeStatistics"/></xsl:template>
<!-- StatsReport/NodeStatistics/Summary template -->
<xsl:template match="Summary">
<table border="0">
<tr>
<td class="bg"><b>Time Saved:</b></td>
<td class="bg"><xsl:apply-templates select="TimeSaved"/></td>
</tr>
<tr>
<td class="bg"><b>Total Packets:</b></td>
<td class="bg"><xsl:apply-templates select="Packets"/></td>
</tr>
<tr>
<td class="bg"><b>Total Bytes:</b></td>
<td class="bg"><xsl:apply-templates select="Bytes"/></td>
</tr>
<tr>
<td class="bg"><b>Nodes:</b></td>
<td class="bg"><xsl:apply-templates select="NodeCount"/></td>
</tr>
</table>
</xsl:template>
<!-- StatsReport/NodeStatistics/Summary/TimeSaved template -->
<xsl:template
match="TimeSaved"><xsl:eval>(this.nodeTypedValue)</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Summary/Packets template -->
<xsl:template
match="Packets"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Summary/Bytes template -->
<xsl:template match="Bytes"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Summary/NodeCount template -->
<xsl:template
match="NodeCount"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Stats template -->
<xsl:template match="Stats"><xsl:apply-templates
select="NodeStat"/></xsl:template>
<!-- StatsReport/NodeStatistics/Stats/PhysNodeStat/BytesOut template
-->
<xsl:template
match="BytesSent"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Stats/PhysNodeStat/PktsOut template -->
<xsl:template
match="PacketsSent"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Stats/PhysNodeStat/BytesIn template -->
<xsl:template
match="BytesReceived"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Stats/PhysNodeStat/PktsIn template -->
<xsl:template
match="PacketsReceived"><xsl:eval>formatNumber(this.nodeTypedValue,
"#,###,###,##0")</xsl:eval></xsl:template>
<!-- StatsReport/NodeStatistics/Stats/PhysNodeStat template -->
<xsl:template match="NodeStat">
<tr>
<td class="rl" style="color:#000000" rowspan="2"><tt><xsl:value-of
select="Addr"/></tt></td>
<td class="rl" colspan="1"><img src="RedBar.gif" height="11"
alt="Sent %"><xsl:attribute
name="width"><xsl:eval>formatNumber(this.selectSingleNode("BytesSent").nodeTypedValue
/
this.selectSingleNode("/StatsReport/NodeStatistics/Summary/Bytes").nodeTypedValue,
"##0%")</xsl:eval></xsl:attribute></img></td>
<td class="rl" colspan="1"><img src="RightArrow.gif" height="11"
alt="Sent"/></td>
<td
class="rr"><xsl:eval>formatNumber(this.selectSingleNode("BytesSent").nodeTypedValue
/
this.selectSingleNode("/StatsReport/NodeStatistics/Summary/Bytes").nodeTypedValue,
"##0.000%")</xsl:eval></td>
<td class="rr"><xsl:apply-templates select="BytesSent"/></td>
<td class="rr"><xsl:apply-templates select="PacketsSent"/></td>
</tr>
<tr>
<td class="rl" colspan="1"><img src="BlueBar.gif" height="11"
alt="Received %"><xsl:attribute
name="width"><xsl:eval>formatNumber(this.selectSingleNode("BytesReceived").nodeTypedValue
/
this.selectSingleNode("/StatsReport/NodeStatistics/Summary/Bytes").nodeTypedValue,
"##0%")</xsl:eval></xsl:attribute></img></td>
<td class="rl" colspan="1"><img src="LeftArrow.gif" height="11"
alt="Received"/></td>
<td
class="rr"><xsl:eval>formatNumber(this.selectSingleNode("BytesReceived").nodeTypedValue
/
this.selectSingleNode("/StatsReport/NodeStatistics/Summary/Bytes").nodeTypedValue,
"##0.000%")</xsl:eval></td>
<td class="rr"><xsl:apply-templates select="BytesReceived"/></td>
<td class="rr"><xsl:apply-templates select="PacketsReceived"/></td>
</tr>
<xsl:apply-templates select="NodeStat"/>
</xsl:template>
<!-- StatsReport/NodeStatistics template -->
<xsl:template match="NodeStatistics">
<h1>Node Statistics</h1>
<xsl:apply-templates select="Summary"/>
<table class="tbl">
<thead>
<tr>
<th class="hl">Node</th>
<th class="hc" style="width:200px;">Percentage</th>
<th class="hl"> </th>
<th class="hr">%</th>
<th class="hr">Bytes</th>
<th class="hr">Packets</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="Stats"/>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<StatsReport xmlns="schema:StatsReportSchema.xml"
xmlns:xsl="http://www/w3.org/1999/XSL/Transform">
<NodeStatistics Version="1.0">
<Summary>
<TimeSaved>11/30/2005 15:08:00</TimeSaved>
<Packets>165</Packets>
<Bytes>20243</Bytes>
<NodeCount>55</NodeCount>
</Summary>
<Stats>
<NodeStat>
<Addr>00:06:5B:97:37:CF</Addr>
<PacketsSent>4</PacketsSent>
<BytesSent>508</BytesSent>
<PacketsReceived>0</PacketsReceived>
<BytesReceived>0</BytesReceived>
</NodeStat>
<NodeStat>
<Addr>FF:FF:FF:FF:FF:FF</Addr>
<PacketsSent>0</PacketsSent>
<BytesSent>0</BytesSent>
<PacketsReceived>120</PacketsReceived>
<BytesReceived>13693</BytesReceived>
</NodeStat>
<NodeStat>
<Addr>00:40:80:76:50:00</Addr>
<PacketsSent>41</PacketsSent>
<BytesSent>6180</BytesSent>
<PacketsReceived>4</PacketsReceived>
<BytesReceived>1557</BytesReceived>
</NodeStat>
</Stats>
</NodeStatistics>
</StatsReport>
The js console in mozilla doesn't report any errors about malformed
xml... it just doesn't display anything. The script works in IE. Can
someone please help me with this? I'm having the hardest time getting
the xsl to transform xml in Mozilla. I'd really like to be able to
have my script work cross browser.
Thanks!
Meena