No replies
antibland
antibland's picture
Offline
Leader
Pittsburgh
Last seen: 13 years 25 weeks ago
Pittsburgh
Joined: 2005-01-17
Posts: 603
Points: 0

I'm getting my feet wet with XQuery and am trying to build a query to calculate GPA from an XML file. Any ideas on this? The trouble I'm having is converting grades (A=4, B=3, C=2, etc...) into numbers to perform the calculation on it.

http://www.dustyroaddesigns.com/storage/students.dtd

http://www.dustyroaddesigns.com/storage/students.xml

Sadly, this is all I've got. It prints out all grades per student.

    let $points := 0
    let $result := ""
    for $student in doc("mystudents.xml")//student
    let $grade := $student//grade
    return
    <grades>{$grade}</grades>

output
<grades>
    <grade>B</grade>
    <grade>A</grade>
    <grade>C</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>A</grade>
    <grade>C</grade>
    <grade>B</grade>
    <grade>B</grade>
</grades>

<grades>
    <grade>B</grade>
    <grade>B</grade>
    <grade>C</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>A</grade>
    <grade>C</grade>
    <grade>B</grade>
    <grade>B</grade>
</grades>

<grades>
    <grade>B</grade>
    <grade>A</grade>
    <grade>A</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>B</grade>
    <grade>A</grade>
    <grade>A</grade>
    <grade>B</grade>
    <grade>B</grade>
</grades>

Tags: