Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:08:55+00:00 2026-06-17T21:08:55+00:00

I have a transcript.xml like this and want to calculate the gpa <?xml version=1.0

  • 0

I have a transcript.xml like this and want to calculate the gpa

    <?xml version="1.0" encoding="UTF-8"?>
<transcript>
    <courses>
        <course>
            <code>IK2210</code>        
            <credits>3</credits>
            <grade>A</grade>
        </course>
        <course>
            <code>IB2210</code>
            <credits>3</credits>
            <grade>A</grade>
        </course>
        <course>
            <code>IB2210</code>
            <credits>1</credits>
            <grade>C</grade>
        </course>
        <course>
            <code>ID1234</code>
            <credits>2</credits>
            <grade>B</grade>
        </course>
    </courses>

</transcript>

I imported the transcript like this

<xsl:variable name="transcript" select="document('transcript2.xml')/transcript"/> 

I tried to do this

<xsl:value-of select=" (4*(sum($transcript/courses/course/credits[$transcript/courses/course/grade='A'])) + 3*(sum($transcript/courses/course/credits[$transcript/courses/course/grade='B'])) + 2*(sum($transcript/courses/course/credits[$transcript/courses/course/grade='C'])) + 1*(sum($transcript/courses/course/credits[$transcript/courses/course/grade='D']))) div (sum($transcript/courses/course/credits))"/>

but the parts

(sum($transcript/courses/course/credits[$transcript/courses/course/grade='A']))

sum up all the credits

How can check the condition?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:08:56+00:00Added an answer on June 17, 2026 at 9:08 pm

    I believe your formula would have worked if instead of using:

    (sum($transcript/courses/course/credits[$transcript/courses/course/grade='A']))
    

    You used:

    (sum($transcript/courses/course[grade='A']/credits))
    

    but perhaps this is a bit more concise:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
      <xsl:key name="kGrade" match="credits" use="../grade"/>
    
      <xsl:template match="/">
        <root>
          <xsl:variable name="transcript" select="document('SOTranscript.xml')/transcript" />
          <xsl:apply-templates select="$transcript" mode="getTotal" />
        </root>
      </xsl:template>
    
      <xsl:template match="transcript" mode="getTotal">
        <xsl:value-of
                select="(4 * sum(key('kGrade', 'A')) + 
                      3 * sum(key('kGrade', 'B')) + 
                      2 * sum(key('kGrade', 'C')) + 
                      sum(key('kGrade', 'D'))
                     ) div sum(courses/course/credits)"/>
      </xsl:template>
    </xsl:stylesheet>
    

    When used on your sample input, the result is:

    <root>3.5555555555555553</root>
    

    which I believe is the expected value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that displays transcripts, something like this myapp.com/transcript/1234 The transcripts are
I have minimal knowledge of Javascript, but would like to use this code to
I have this transcript.xml imported as I have another source xml for the xsl
I have 3 classes: Course , CourseEntry and Transcript . In transcript, I have
The setup = I have this class, Transcript: class Transcript(models.Model): body = models.TextField('Body') doPagination
I have an array of hashes with arrays that look something like this: result
Have written all the code in a silverlight class library (dll) and linked this
Have a look at this code: #include <iostream> using namespace std; int main() {
I have this file/string: ----- Transcript of session follows ----- ... while talking to
I have a table whose data looks like this: INSERT INTO `cm_case_notes` (`id`, `case_id`,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.