xml, xsl and ajax

Here should go questions about transforming XML with XSLT and FOP.
bbvic
Posts: 1
Joined: Fri Jun 29, 2007 8:13 pm

xml, xsl and ajax

Post by bbvic »

I am a new to ajax..
I have an error like the below.

document.getElementById("medicalid").innerHTML=xmlDoc.getElementsByTagName("doctors")[0].getElementsByTagName("doctor")[0].childNodes[0].nodeValue;
error says the value is null.

Would you please help me how i can get the node value and i can solve?


[ file name: medical.xsl ]
<xsl:stylesheet version="1.0" xmlns:xalan="http://xml.apache.org/xslt" >
<script>
var xmlHttp

function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}

var url='../stat/medical.html?patient_id=<xsl:value-of select="pid" />&medicalid='+str;

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById("medicalid").innerHTML=xmlDoc.getElementsByTagName("doctors")[0].getElementsByTagName("doctor")[0].childNodes[0].nodeValue;

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>

<table>
<tr>
<td>
<select id="medicalid" name="medicalid" onchange="return stateChanged()">
<xsl:for-each select="/document/stat/medical/hospital/medical">
<option value="{./@medical_field_id}"><xsl:value-of select="./@medical_field_name" /></option>
</xsl:for-each>
</select>
</td>
</tr>
<tr>
<td>
<select id="medicalfield" name="medicalfield" >
<xsl:for-each select="/document/stat/medical/doctors/doctor">
<option value="{./@doctorid}"><xsl:value-of select="./@doctor_name" /></option>
</xsl:for-each>
</select>
</td>
</tr>
</table>
</xsl:stylesheet>


[ file name: ../stat/medical.xml ]


<?xml version="1.0"?>
<document>
<testarea>
<stat>
<xsp:logic>

String medicalid=<xsp-request:get-parameter name="medicalid"/>';

</xsp:logic>

<medical>
<hospital>
<medical medical_field_id="PS" medical_field_name="Plastic Surgeory"></medical>
<medical medical_field_id="IM" medical_field_name="Internal Medicine"></medical>
<medical medical_field_id="OP" medical_field_name="Orthepedics"></medical>
</hospital>

<!-- if medicalid is null, it displays nothing, if medicalid is not null, it gets medicalid (get-parameter). -->
<doctors>
<doctor doctorid="MDPS" doctor_name="Test_2 M.D"></medical>
<doctor doctorid="MDPS" doctor_name="Test_1 M.D"></medical>
<doctor doctorid="MDPS" doctor_name="Test_3 M.D"></medical>
</doctors>
<medical>
<stat>
<testarea>
<document>
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

getElementById("medicalid")
This implies you're getting an element like so:
<element id="medicalid">

I think you need to find a medical element where medical_field_id="PS" instead.

Either change your source to use id attributes, or use getElementsByTagName("medical") and loop through.
Post Reply