Hi Folks,
Long time reader – First time poster.
I haven’t long started programming with Ajax technology and I have cropped upon an issue that has really stumped me.
I have an XSL file with the following contents:
[CODE]
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:template match=”/”>
<html>
<body>
<h2>Footballl</h2>
<table border=”1″>
<tr bgcolor=”#9acd32″>
<th>Player</th>
<th>Team</th>
<th>Number</th>
<th>Position</th>
<th>Field Area</th>
</tr>
<xsl:for-each select=”player-list/player”>
<xsl:if test=”position=’Defender’ and fieldarea=’Right Back'”>
<tr>
<td><xsl:value-of select=”name”/></td>
<td><xsl:value-of select=”team”/></td>
<td><xsl:value-of select=”number”/></td>
<td><xsl:value-of select=”position”/></td>
<td><xsl:value-of select=”fieldarea”/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The XSL displays the initial output onto the web page: [url]www.dbirkin.co.uk/uni/wdd2
However, when using JavaScript pass changes into the XSL:IF test statement to change the data on the screen.
The JavaScript code is as follows:
[CODE]
var xml, xsl;
xml = loadXMLDoc(“xml/players/players.xml”);
xsl = loadXMLDoc(“xml/players/players.xsl”);
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xhttp.open(“GET”,dname,false);
xhttp.send(“”);
return xhttp.responseXML;
}
function loadPlayerData(){
//xml=loadXMLDoc(“xml/players/players.xml”);
//xsl=loadXMLDoc(“xml/players/players.xsl”);
displayPlayerResult();
}
function displayPlayerResult()
{
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById(“players”).innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById(“players”).innerHTML=””;
document.getElementById(“players”).appendChild(resultDocument);
}
}
function MM_jumpMenu1(selObj, selObj2)
{
var selObj = document.getElementById(“positionmenu”); // Set value of Drop Down Menu 1’s Selected Value
var selObj2 = document.getElementById(“field”); // Set value of Drop Down Menu 2’s Selected Value
[COLOR=”Red”]x=xsl.getElementsByTagName(“xsl:if”)[0]; // sets element for ie
alert(x); // Returns a “Unspecified” or “null” Error
if (x==null) {
x=xsl.getElementsByTagName(“if”)[0];// sets element for other browsers
alert(x); // Returns an “unspecified” or “null” error
}[/COLOR]
var testoption = (“position='” + selObj.value + “‘ and fieldarea='” + selObj2.value + “‘”); // Concatanated string for input to the TEST statement
alert (testoption);
x.setAttribute(“test”, testoption); //”position=’Defender'”
displayPlayerResult();
}
The code in RED is where my error is occuring. Object is apparently unspecified and the browser is not recognising the XSL:IF attribute within the XSL file. I don’t know if you need to state XSL:IF differently but when i used the same function with XSL:SORT it works fine.
Any help would be highly appreciated.
Many thanks,
David