Question 3: In these exercises, you will be working with a small XML data set dr
ID: 3829073 • Letter: Q
Question
Question 3:
In these exercises, you will be working with a small XML data set drawn from the Stanford course catalog. There are multiple departments, each with a department chair, some courses, and professors and/or lecturers who teach courses. The XML data is here (https://prod-c2g.s3.amazonaws.com/db/Winter2013/files/courses-noID.xml).
Write a query in XPath or XQuery
1-Return all Title elements (of both departments and courses).
2-Return last names of all department chairs.
3-Return titles of courses with enrollment greater than 500.
4-Return titles of departments that have some course that takes "CS106B" as a prerequisite.
5-Return last names of all professors or lecturers who use a middle initial. Don't worry about eliminating duplicates.
6-Return the count of courses that have a cross-listed course (i.e., that have "Cross-listed" in their description).
7-Return the average enrollment of all courses in the CS department.
8-Return last names of instructors teaching at least one course that has "system" in its description and enrollment greater than 100.
Explanation / Answer
1-Return all Title elements (of both departments and courses)
<xsl:for-each select = "Course_Catalog/Department">
<tr>
<td><xsl:value-of select = "Title"/></td>
</tr>
<xsl:for-each select = "Course_Catalog/Department/Course">
<tr>
<td><xsl:value-of select = "Title"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
2-Return last names of all department chairs
<xsl:for-each select = "Course_Catalog/Department/Chair/Professor">
<tr>
<td><xsl:value-of select = "Last_Name"/></td>
</tr>
</xsl:for-each>
3-Return titles of courses with enrollment greater than 500.
<xsl:for-each select = "Course_Catalog/Department/Course[@Enrollment > 500]">
<tr>
<td><xsl:value-of select = "Title"/></td>
</tr>
</xsl:for-each>
4-Return titles of departments that have some course that takes "CS106B" as a prerequisite
<xsl:for-each select = "Course_Catalog/Department/">
<xsl:if test = "Course_Catalog/Department/Course[@Number] = CS106B">
<tr>
<td><xsl:value-of select = "Course_Catalog/Department/Title"/></td>
</tr>
</xsl:if>
</xsl:for-each>
5-Return last names of all professors or lecturers who use a middle initial. Don't worry about eliminating duplicates.
<xsl:for-each select = "Course_Catalog/Department/Chair/Professor">
<xsl:if test = "Course_Catalog/Department/Chair/Professor[@Middle_Initial]">
<tr>
<td><xsl:value-of select = "Last_Name"/></td>
</tr>
</xsl:if>
</xsl:for-each>
6-Return the count of courses that have a cross-listed course (i.e., that have "Cross-listed" in their description)
<xsl:for-each sLecturerelect = "Course_Catalog/Department/Course/Description= Cross-listed">
<tr>
<td><xsl:value-of select = "count(Course_Catalog/Department/Course/Description)"/></td>
</tr>
</xsl:for-each>
7-Return the average enrollment of all courses in the CS department.
<xsl:for-each select = "Course_Catalog/Department[@Code]= CS">
<xsl:for-each select = "Course_Catalog/Department/Course[@Enrollment]">
<tr>
<td><xsl:value-of select = "avg(Enrollment)"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
8-Return last names of instructors teaching at least one course that has "system" in its description and enrollment greater than 100.
<xsl:for-each select = "Course_Catalog/Department/Course[@Enrollment] > 100">
<xsl:if test = "Course_Catalog/Department/Course/Description[contains(.., "system")]">
<tr>
<td><xsl:value-of select = "Course_Catalog/Department/Course/Instructors/[Lecturer/Last_Name or Professor/Last_Name]"/></td>
</tr>
</xsl:if>
</xsl:for-each>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.