Link to home
Start Free TrialLog in
Avatar of toymachiner62
toymachiner62Flag for United States of America

asked on

XPath find a node if contains duplicate nodes

I need to find the sections that are taught by 2 instructors.

The closest thing that i can even think of to achieve this is    //section[/instructor > 2]    but this would check to see if the value of instructor is greater than 2 i believe.
<?xml version="1.0" encoding="UTF-8"?>
 
 
 
<courses>
	<course number = "CS341" credits = "4.0">
    <title>Data Structures</title>
    <section number = "01" id = "X001780" delivery = "Classroom">
      <enrollment>4</enrollment>
      <date>
        <start_date>08/26/2008</start_date>
        <end_date>12/11/2008</end_date>
      </date>
      <days>T TH</days>
      <time>
        <start_time>4:00pm </start_time>
        <end_time>5:50pm</end_time>
      </time>
      <room campus = "Rochester">EA244</room>
      <instructor>
        <first>Nicole</first>
        <last>Anderson</last>
      </instructor>
	  </section>
	  <section number = "CS341" id = "X001788" delivery = "On-line">
      <enrollment>0</enrollment>
      <date>
        <start_date>08/29/2008</start_date>
        <end_date>12/12/2008</end_date>
      </date>
      <days></days>
      <time>
        <start_time></start_time>
        <end_time></end_time>
      </time>
      <room campus = "Rochester"></room>
      <instructor>
        <first>Nicole</first>
        <last>Anderson</last>
      </instructor>
      <instructor>
        <first>Chi-Cheng</first>
        <last>Lin</last>
      </instructor>
	  </section>
  </course>
  <course number = "CS368" credits = "3.0">
    <title>Introduction to Bioinformatics</title>
    <section number = "01" id = "X001781" delivery = "ITV">
      <enrollment>3</enrollment>
      <date>
        <start_date>08/27/2008</start_date>
        <end_date>12/10/2008</end_date>
      </date>
      <days>W</days>
      <time>
        <start_time>6:00pm </start_time>
        <end_time>8:40pm</end_time>
      </time>
      <room campus = "Rochester">AT102</room>
      <instructor>
        <first>Chi-Cheng</first>
        <last>Lin</last>
      </instructor>
      <instructor>
        <first>Mingrui</first>
        <last>Zhang</last>
      </instructor>
	    </section>
    </course>
  <course number = "CS375" credits = "4.0">
    <title>Computer Systems</title>
    <section number = "01" id = "X001782" delivery = "Classroom">
     <enrollment>12</enrollment>
     <date>
       <start_date>08/25/2008</start_date>
       <end_date>12/10/2008</end_date>
     </date>
     <days>M W</days>
     <time>
       <start_time>4:00pm </start_time>
       <end_time>5:50pm</end_time>
     </time>
     <room campus = "Rochester">EA244</room>
     <instructor>
       <first>Nicole</first>
       <last>Anderson</last>
     </instructor>
	  </section>
  </course>
  <course number = "CS415" credits = "3.0">
    <title>Principles of Programming Languages</title>
    <section number = "01" id = "X001784" delivery = "Classroom">
      <enrollment>13</enrollment>
      <date>
        <start_date>08/26/2008</start_date>
        <end_date>12/11/2008</end_date>
      </date>
      <days>T TH</days>
      <time>
        <start_time>4:00pm </start_time>
        <end_time>5:20pm</end_time>
      </time>
      <room campus = "Rochester">EA246</room>
      <instructor>
        <first>Hugh</first>
        <last>Ouellette</last>
      </instructor>
	  </section>
  </course>
</courses>

Open in new window

Avatar of Capt_Jack
Capt_Jack
Flag of Australia image

if i understand your requirement correctly then you want to list the section id's that have more than one instructor

Try this
       /courses/course/section[count(instructor) > 1]/@id

It gives two values --> section id X001788 and X001781


Cheers....
ASKER CERTIFIED SOLUTION
Avatar of Capt_Jack
Capt_Jack
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toymachiner62

ASKER

Thanks. I guess i didn't know that you can use the count function with an arithmetic expression. that helps a lot