i have this xml
<Edu>
<Department>
<Student>
<name>jack</name>
<Std_ID>12345678</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>melin</name>
<Std_ID>56784921</Std_ID>
<Degree>PHD</Degree>
</Student>
<Student>
<name>sali</name>
<Std_ID>54673821</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>parisa</name>
<Std_id>54321876</Std_id>
<Degree>BS</Degree>
</Student>
<Student>
<name>caty</name>
<Std_ID>87654321</Std_ID>
<Degree>MS</Degree>
</Student>
</Department>
<Course>
<name>programing</name>
<Student>
<name>jack</name>
<Std_ID>12345678</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>sali</name>
<Std_ID>54673821</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>parisa</name>
<Std_id>54321876</Std_id>
<Degree>BS</Degree>
</Student>
</Course>
<Course>
<name>network</name>
<Student>
<name>jack</name>
<Std_ID>12345678</Std_ID>
<Degree>MS</Degree>
</Student>
</Course>
<Course>
<name>Database</name>
<Student>
<name>jack</name>
<Std_ID>12345678</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>caty</name>
<Std_ID>87654321</Std_ID>
<Degree>MS</Degree>
</Student>
</Course>
<Course>
<Student>
<name>jack</name>
<Std_ID>12345678</Std_ID>
<Degree>MS</Degree>
</Student>
<Student>
<name>caty</name>
<Std_ID>87654321</Std_ID>
<Degree>MS</Degree>
</Student>
</Course>
</Edu>
and i want to list student with MS Degree that has more than 2 course,or BS Student that has more than one course. i means that i want name of student with ms degree that has more than 2 course or student with bs degree that has more than one course.i want both of these list. this is my xquery: but it does not work:
for $i in doc("XMLFile_Q2.xml")/Edu/Department/Student[Degree="MS" or Degree="BS"]
let $counter :=0
for $a in doc("XMLFile_Q2.xml")/Edu/Course
where $a/Student[name]=$i[name]
let $counter := $counter+1
return if($a/Student[Degree]="MS" and $counter gt 2 )
then $a/Student/name
else if($a/Student[Degree]="BS" and $counter gt 1)
then $a/Student/name/text()
else()