473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XML Node Count

I'm trying to populate two select list using the following XML file:

<HealthServices>
<Divisions>
<Division>Home Office</Division>
<Facility>Administration</Facility>
<Facility>Finance</Facility>
<Facility>Human Resources</Facility>
<Facility>Operations</Facility>
</Divisions>
<Divisions>
<Division>Hospital</Division>
<Facility>Facility1</Facility>
<Facility>Facility2</Facility>
</Divisions>
<Divisions>
<Division>Sr. Housing</Division>
<Facility>Facility3</Facility>
<Facility>Facility4</Facility>
</Divisions>
</HealthServices>

Here is the script that I'm using:

<script language="JavaScript" type="text/javascript">

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");

var allDivisions;
var allDivisionNodes;
var allFacilityNodes;

function init(){

xmlDoc.async = false;
xmlDoc.load("./xml/esf_data4.xml");
xmlDoc.setProperty("SelectionLanguage", "XPath");

allDivisions = xmlDoc.selectNodes("//Divisions");
allDivisionNodes = xmlDoc.selectNodes("//Division");
allFacilityNodes = xmlDoc.selectNodes(".//Facility");

populateDivisionList();
populateFacilityList();
}

function populateDivisionList(){
clearSelect('OBDataset_Division_1');

var lstDivision = document.getElementById('OBDataset_Division_1');

for (var i=0; i<allDivisions.length; i++) {
var thisDivisionNameTxt = allDivisions[i].selectNodes("./Division")[0].text;
var newOption = document.createElement("option");
newOption.innerHTML=thisDivisionNameTxt;
newOption.value = allDivisions[i].selectNodes("./Division")[0].text;

lstDivision.appendChild(newOption);
}
}

function populateFacilityList(){
clearSelect('OBDataset_Facility_1');

var lstFacility = document.getElementById('OBDataset_Facility_1');

for (var i=0; i<allFacilityNodes.length; i++) {
var thisFacilityNameTxt = allDivisions[0].selectNodes("./Facility")[i].text;
var newOption = document.createElement("option");
newOption.innerHTML=thisFacilityNameTxt;
newOption.value = allDivisions[0].selectNodes("./Facility")[i].text;

lstFacility.appendChild(newOption);
}
}

function clearSelect(list){
var lstSelect = document.getElementById(list);
lstSelect.length = 0;
}

</script>

I'm getting an error because my for loop is looping too many times because the length of allFacilityNodes is counting all Facility nodes in the list and I only want the ones for a selected Division. How can I fix this?
Jul 12 '07 #1
1 12887
jkmyoung
2,057 Expert 2GB
i<allFacilityNodes.length
There seems to be the problem.
You'd want allDivisions[0].selectNodes("./Facility").length instead.

for (var i=0; i<allDivisions[0].selectNodes("./Facility").length; i++) {
Jul 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andy Fish | last post by:
Hi, I just found this template in someone else's xslt (it's Microsoft's "word2html" stylesheet to convert WordProcessingML to HTML) <xsl:template match="WX:sect"> <xsl:variable...
8
by: Ryan Stewart | last post by:
Putting the following code in a page seems to make it go into an infinite loop unless you give it a very simple node to work with. Either that or it's very very slow. I'm somewhat new to this,...
4
by: Alfred Taylor | last post by:
I essentially need a countif() function for xsl. Something to where I could do countif(node-set, condition). Rather than try to get too extreme, i decided to just write one for my countif() with...
1
by: jesper_lofgren | last post by:
Hello, Iam using Treeview control in asp.net 2.0. But have a problem. I use NavigateUrl BUT then viewstate is lost when clicked on a link i the menu. And the selected node is lost. Then i...
9
by: anunaygupta | last post by:
Hello all, I have a data structures problem. Assume there are 2 linked lists L1 and L2. They merge into some node. L1 1->2->3->4->5->6 / L2 8->7->9->/ L1 and L2 merge in node with value...
0
by: pavlaras | last post by:
hi all its been a while since i've worked on a VB program and im currently facing difficulties with the following code.I'm trying to create a diagram with nodes which you can manipulate and enter...
3
by: gregmcmullinjr | last post by:
Hi All, I would like to use XSLT to replace all <unodes that are children of a <bnode with a new <headingnode. Also, if the <bnode has no other children than remove it as well. For example: ...
3
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
20
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have to populate columns that consist of some textfields and some input boxes the problem is at the mozilla's end, it creates a new node and appends the...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.