Sample Solutions for the XPath Exercises of Lab 3 ================================================= These are possible ways to express the queries of Lab 3. There are also many equivalent solutions. 1. Which course has the lowest enrollment? Note: There are some courses without enrollment figures. //Course[@Enrollment][not(@Enrollment > //@Enrollment)] 2. Which courses have at least two instructors? //Course[count(id(@Instructors)) >= 2] 3. Return the titles of the courses taught by Prof. Aiken. //Course[id(@Instructors)/Last_Name="Aiken"]/Title 4. Who are the co-teachers of Jerry Cain, that is, which people are jointly teaching a course with Jerry Cain? id(//Course[id(@Instructors)[Last_Name = "Cain" and First_Name = "Jerry"]] /@Instructors) 5. Which are the courses taught by Jerry Cain, but not by Mehran Sahami? //Course[id(@Instructors)[Last_Name = "Cain" and First_Name = "Jerry"]] [not(id(@Instructors)[Last_Name = "Sahami" and First_Name = "Mehran"])] 6. Return the titles of courses taught by instructors from the department of Linguistics. //Course[id(@Instructors)/parent::Department[Title="Linguistics"]]/Title 7. Which courses have prerequisite courses that are taught at another department than the course itself? //Course[id(@Prerequisites)/parent::Department/Title != parent::Department/Title] 8. Which courses are taught by an instructor who also teaches one of the course prerequisites? //Course[id(@Instructors)=id(id(@Prerequisites)/@Instructors)] 9. Which courses have a lower enrollment than any of their prerequisites? //Course[@Enrollment < id(@Prerequisites)/@Enrollment] 10. Which courses are taught by a lecturer? //Course[id(@Instructors)[name()="Lecturer"]] 11. Which instructors (i.e., professors or lecturers) do not have a middle initial? //*[name()="Professor" or name()="Lecturer"][not(Middle_Initial)]