m0nkeymafia
07-18-2006, 05:21 PM
Hi,
I have an XSL stylesheet which works perfectly and some AJAX code to pull the XML and XSL off the server, the AJAX code is used throughout all my pages all of which work fine, bar 2, which generate FORM components on the fly using the stylesheet.
In IE only they do not show and I have no idea why, they work fine in firefox and the AJAX code performs as expected on every other page bar this.
Is this due to a lack of support from IE or have I made a mistake? I am using an XML / XSL editor that also validates and that has found no issues!!
Could anyone shed any light please!
THANKYOU!!!
----------------------
Example XML File:
----------------------
<SMARTLANE>
<StoreConfig storename="MarksNSparks">
<LaneConfig group = "0" number = "1-15"></LaneConfig>
<DoorConfig number = "30"></DoorConfig>
</StoreConfig>
</SMARTLANE>
----------------------
XSL File
----------------------
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" />
<xsl:template match="/SMARTLANE/StoreConfig">
<form name="SubmitStoreConfig" method="post">
<div class="configSection">
<h3><xsl:value-of select="@storename"/> Store Configuration</h3>
<table>
<tr>
<th>Type</th>
<th>Lanes/CanID</th>
<th>Group</th>
<th><img src="Graphics/delete.jpg" /></th>
</tr>
<xsl:apply-templates/>
</table>
</div>
</form>
</xsl:template>
<xsl:template match="LaneConfig|DoorConfig">
<xsl:variable name="number"><xsl:value-of select="@number"/></xsl:variable>
<xsl:variable name="group">
<xsl:choose>
<xsl:when test="@group != ''"><xsl:value-of select="@group"/></xsl:when>
<xsl:otherwise>N/A</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="name"><xsl:value-of select="name()"/></xsl:variable>
<xsl:variable name="class">
<xsl:value-of select="position()"/>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">odd</xsl:when>
<xsl:otherwise>even</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr class="{$class}">
<td><xsl:value-of select="$name"/><input type="hidden" name="type" value='{$name}' /></td>
<td><input type="text" name="number" value='{$number}' size="4"/></td>
<td><input type="text" name="group" value='{$group}' size="2" /></td>
<td><img src="Graphics/delete.jpg" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
----------------------
Javascript
N.b. please note the javascript has been stripped back in an attempt to trap leaks in IE, if anyone could also suggest fixes for this thatd be great!!!
----------------------
//==========================================================================
var gFile = null;
var gObjId = null;
var gXSLT = null;
var xmlhttp = null;
var gTimeout = 6000;
//==========================================================================
function InitialSetup(xml, obj, xsl)
{
gFile = xml; xml = null;
gObjId = obj; obj = null;
if (window.ActiveXObject)
{
gXSLT = new ActiveXObject("Microsoft.XMLDOM");
gXSLT.async = false;
gXSLT.load(xsl);
}
else
{
gXSLT = new XSLTProcessor();
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", xsl, false);
myXMLHTTPRequest.send(null);
var xslRef = myXMLHTTPRequest.responseXML;
// Finally import the .xsl
gXSLT.importStylesheet(xslRef);
}
xsl = null;
FnGetXML();
}
// =========================================================================
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
if (xmlhttp != null)
{
xmlhttp.onreadystatechange=fnLoadedXML;
xmlhttp.open("GET",gFile,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
//==========================================================================
function checkReadyState()
{
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
return true;
}
else
{
document.getElementById(gObjId).innerHTML = "Error retrieving XML data";
}
}
}
//==========================================================================
function FnGetXML()
{
if (gTimeout > 0)
{
setTimeout("FnGetXML()",gTimeout);
//setTimeout("FnGetXML()",50);
}
loadXMLDoc()
}
//==========================================================================
function fnLoadedXML()
{
if (!checkReadyState())
{
return;
}
var target = document.getElementById(gObjId);
xmlRef = xmlhttp.responseXML;
target.innerHTML = "";
var outputXHTML = null;
if (window.ActiveXObject)
{
outputXHTML = xmlRef.transformNode(gXSLT);
target.innerHTML = outputXHTML;
}
else
{
outputXHTML = gXSLT.transformToFragment(xmlRef, document);
target.appendChild(outputXHTML);
}
//alert(outputXHTML);
outputXHTML = null;
target = null;
xmlhttp = null;
}
I have an XSL stylesheet which works perfectly and some AJAX code to pull the XML and XSL off the server, the AJAX code is used throughout all my pages all of which work fine, bar 2, which generate FORM components on the fly using the stylesheet.
In IE only they do not show and I have no idea why, they work fine in firefox and the AJAX code performs as expected on every other page bar this.
Is this due to a lack of support from IE or have I made a mistake? I am using an XML / XSL editor that also validates and that has found no issues!!
Could anyone shed any light please!
THANKYOU!!!
----------------------
Example XML File:
----------------------
<SMARTLANE>
<StoreConfig storename="MarksNSparks">
<LaneConfig group = "0" number = "1-15"></LaneConfig>
<DoorConfig number = "30"></DoorConfig>
</StoreConfig>
</SMARTLANE>
----------------------
XSL File
----------------------
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no" />
<xsl:template match="/SMARTLANE/StoreConfig">
<form name="SubmitStoreConfig" method="post">
<div class="configSection">
<h3><xsl:value-of select="@storename"/> Store Configuration</h3>
<table>
<tr>
<th>Type</th>
<th>Lanes/CanID</th>
<th>Group</th>
<th><img src="Graphics/delete.jpg" /></th>
</tr>
<xsl:apply-templates/>
</table>
</div>
</form>
</xsl:template>
<xsl:template match="LaneConfig|DoorConfig">
<xsl:variable name="number"><xsl:value-of select="@number"/></xsl:variable>
<xsl:variable name="group">
<xsl:choose>
<xsl:when test="@group != ''"><xsl:value-of select="@group"/></xsl:when>
<xsl:otherwise>N/A</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="name"><xsl:value-of select="name()"/></xsl:variable>
<xsl:variable name="class">
<xsl:value-of select="position()"/>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">odd</xsl:when>
<xsl:otherwise>even</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr class="{$class}">
<td><xsl:value-of select="$name"/><input type="hidden" name="type" value='{$name}' /></td>
<td><input type="text" name="number" value='{$number}' size="4"/></td>
<td><input type="text" name="group" value='{$group}' size="2" /></td>
<td><img src="Graphics/delete.jpg" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
----------------------
Javascript
N.b. please note the javascript has been stripped back in an attempt to trap leaks in IE, if anyone could also suggest fixes for this thatd be great!!!
----------------------
//==========================================================================
var gFile = null;
var gObjId = null;
var gXSLT = null;
var xmlhttp = null;
var gTimeout = 6000;
//==========================================================================
function InitialSetup(xml, obj, xsl)
{
gFile = xml; xml = null;
gObjId = obj; obj = null;
if (window.ActiveXObject)
{
gXSLT = new ActiveXObject("Microsoft.XMLDOM");
gXSLT.async = false;
gXSLT.load(xsl);
}
else
{
gXSLT = new XSLTProcessor();
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", xsl, false);
myXMLHTTPRequest.send(null);
var xslRef = myXMLHTTPRequest.responseXML;
// Finally import the .xsl
gXSLT.importStylesheet(xslRef);
}
xsl = null;
FnGetXML();
}
// =========================================================================
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
if (xmlhttp != null)
{
xmlhttp.onreadystatechange=fnLoadedXML;
xmlhttp.open("GET",gFile,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
//==========================================================================
function checkReadyState()
{
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
return true;
}
else
{
document.getElementById(gObjId).innerHTML = "Error retrieving XML data";
}
}
}
//==========================================================================
function FnGetXML()
{
if (gTimeout > 0)
{
setTimeout("FnGetXML()",gTimeout);
//setTimeout("FnGetXML()",50);
}
loadXMLDoc()
}
//==========================================================================
function fnLoadedXML()
{
if (!checkReadyState())
{
return;
}
var target = document.getElementById(gObjId);
xmlRef = xmlhttp.responseXML;
target.innerHTML = "";
var outputXHTML = null;
if (window.ActiveXObject)
{
outputXHTML = xmlRef.transformNode(gXSLT);
target.innerHTML = outputXHTML;
}
else
{
outputXHTML = gXSLT.transformToFragment(xmlRef, document);
target.appendChild(outputXHTML);
}
//alert(outputXHTML);
outputXHTML = null;
target = null;
xmlhttp = null;
}