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

  • Home
  • SEARCH
  • 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 7549741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:01:28+00:00 2026-05-30T10:01:28+00:00

I have been struggling for days to determine how to take an XML file

  • 0

I have been struggling for days to determine how to take an XML file of game results (teams and final scores) and generate a team standings list that shows each team along with how many times they won, lost or tied. The results should also be sorted by total wins, but I can’t even figure out a good method of calculating the wins/losses let alone sorting by the results. I know it must involve muenchian grouping, and I’ve coded the part that finds all distinct teams but am stumped where to go from there. Any help would be GREATLY appreciated.

games.xml

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="games.xsl"?>

<Games>

  <Game>
    <Home>Team A</Home>
    <Away>Team B</Away>
    <Home_Score>20</Home_Score>
    <Away_Score>15</Away_Score>
  </Game>

  <Game>
    <Home>Team C</Home>
    <Away>Team D</Away>
    <Home_Score>12</Home_Score>
    <Away_Score>18</Away_Score>
  </Game>

  <Game>
    <Home>Team A</Home>
    <Away>Team C</Away>
    <Home_Score>8</Home_Score>
    <Away_Score>8</Away_Score>
  </Game>

  <Game>
    <Home>Team B</Home>
    <Away>Team D</Away>
    <Home_Score>6</Home_Score>
    <Away_Score>14</Away_Score>
  </Game>

  <Game>
    <Home>Team D</Home>
    <Away>Team C</Away>
    <Home_Score>9</Home_Score>
    <Away_Score>11</Away_Score>
  </Game>

  <Game>
    <Home>Team C</Home>
    <Away>Team A</Away>
    <Home_Score>13</Home_Score>
    <Away_Score>13</Away_Score>
  </Game>

</Games>

games.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- Key for identifying teams -->
  <xsl:key name="unique-teams" match="/Games/Game" use="Home" />

  <xsl:template match="/">
    <html>
    <head>
    <title>Team Standings</title>
    </head>
    <body>

        <!-- Get distinct teams, sort by team name -->
        <xsl:apply-templates select="//Game[generate-id() = generate-id(key('unique-teams', Home)[1])]">
            <xsl:sort select="Home" />
        </xsl:apply-templates>

    </body>
    </html>
  </xsl:template>

  <xsl:template match="Game">

    <!-- Current team -->
    <xsl:variable name="selectedteam" select="Home" />

    <!-- Output each unique team name to the screen -->
    <h1><xsl:value-of select="$selectedteam"/></h1>

    <!-- Loop through all games to calculate totals??? -->
    <xsl:for-each select="//Game">    
    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>
  • 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-05-30T10:01:30+00:00Added an answer on May 30, 2026 at 10:01 am

    You want something like this (XSLT 1.0):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:key name="kTeamByName" match="Home|Away" use="."/>
    
     <xsl:template match="/*">
    
     <table border="1">
      <tr>
       <td>Team</td><td>W</td><td>D</td><td>L</td>
      </tr>
          <xsl:apply-templates select=
          "(*/Home | */Away)
            [generate-id()
            =
             generate-id(key('kTeamByName', .)[1])
            ]
          ">
          <xsl:sort data-type="number" order="descending" select=
           "count(key('kTeamByName', .)
                     [self::Home
                    and
                      ../Home_Score > ../Away_Score
                    or
                      self::Away
                    and
                      ../Away_Score > ../Home_Score
                     ]
                 )
           "/>
    
          </xsl:apply-templates>
      </table>
     </xsl:template>
    
     <xsl:template match="Home|Away">
      <tr>
       <td>
        <xsl:value-of select="."/>
       </td>
       <td>
        <xsl:value-of select=
        "count(key('kTeamByName', .)
                     [self::Home
                    and
                      ../Home_Score > ../Away_Score
                    or
                      self::Away
                    and
                      ../Away_Score > ../Home_Score
                     ]
                 )"/>
       </td>
       <td>
        <xsl:value-of select=
        "count(key('kTeamByName', .)
                     [../Home_Score = ../Away_Score]
                 )"/>
       </td>
       <td>
        <xsl:value-of select=
        "count(key('kTeamByName', .)
                     [self::Home
                    and
                      ../Away_Score > ../Home_Score
                    or
                      self::Away
                    and
                      ../Home_Score > ../Away_Score
                     ]
                 )"/>
       </td>
      </tr>
     </xsl:template>
    
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <Games>
        <Game>
            <Home>Team A</Home>
            <Away>Team B</Away>
            <Home_Score>20</Home_Score>
            <Away_Score>15</Away_Score>
        </Game>
        <Game>
            <Home>Team C</Home>
            <Away>Team D</Away>
            <Home_Score>12</Home_Score>
            <Away_Score>18</Away_Score>
        </Game>
        <Game>
            <Home>Team A</Home>
            <Away>Team C</Away>
            <Home_Score>8</Home_Score>
            <Away_Score>8</Away_Score>
        </Game>
        <Game>
            <Home>Team B</Home>
            <Away>Team D</Away>
            <Home_Score>6</Home_Score>
            <Away_Score>14</Away_Score>
        </Game>
        <Game>
            <Home>Team D</Home>
            <Away>Team C</Away>
            <Home_Score>9</Home_Score>
            <Away_Score>11</Away_Score>
        </Game>
        <Game>
            <Home>Team C</Home>
            <Away>Team A</Away>
            <Home_Score>13</Home_Score>
            <Away_Score>13</Away_Score>
        </Game>
    </Games>
    

    the wanted, correct result is produced:

    <table border="1">
       <tr>
          <td>Team</td>
          <td>W</td>
          <td>D</td>
          <td>L</td>
       </tr>
       <tr>
          <td>Team D</td>
          <td>2</td>
          <td>0</td>
          <td>1</td>
       </tr>
       <tr>
          <td>Team A</td>
          <td>1</td>
          <td>2</td>
          <td>0</td>
       </tr>
       <tr>
          <td>Team C</td>
          <td>1</td>
          <td>2</td>
          <td>1</td>
       </tr>
       <tr>
          <td>Team B</td>
          <td>0</td>
          <td>0</td>
          <td>2</td>
       </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling for a few days trying to find out how come
So I've been struggling with this for a couple days now. I have a
I have been struggling with this for days now. I am trying to register
I have been struggling with this question for several days. What is the age
So, for the past few days I have been struggling to understand how to
I have been struggling with that for 4 days now. I have a very
I have been struggling with this for three days, I want to do a
We have been struggling with this for a few days and have done lots
I have been struggling with a problem for a couple of days now with
I have been struggling with getting this to work for a number of days

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.