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 shows each team along with how many times they won, lost or tied based on game status(played). I was able to display team standings on both game status(played and pending). I want to display team standings that are played only.Any help would be greatly appreciated.

here is my xml code:

<Schedule>
    <game status="played">
      <Home_Team>A</Home_Team>
      <Away_Team>B</Away_Team>
      <Date>2013-06-15</Date>
      <Home_Team_Score>3</Home_Team_Score>
      <Away_Team_Score>3</Away_Team_Score>
   </game>

   <game status="played">
      <Home_Team>A</Home_Team>
      <Away_Team>C</Away_Team>
      <Date>2013-06-17</Date>
      <Home_Team_Score>7</Home_Team_Score>
      <Away_Team_Score>4</Away_Team_Score>
   </game>

   <game status="played">
      <Home_Team>C</Home_Team>
      <Away_Team>A</Away_Team>
      <Date>2013-06-19</Date>
      <Home_Team_Score>3</Home_Team_Score>
      <Away_Team_Score>3</Away_Team_Score>
   </game>

   <game status="played">
      <Home_Team>D</Home_Team>
      <Away_Team>C</Away_Team>
      <Date>2013-06-19</Date>
      <Home_Team_Score>8</Home_Team_Score>
      <Away_Team_Score>7</Away_Team_Score>
   </game>

   <game status="pending">
      <Home_Team>B</Home_Team>
      <Away_Team>C</Away_Team>
      <Date>2013-07-25</Date>
      <Home_Team_Score>0</Home_Team_Score>
      <Away_Team_Score>0</Away_Team_Score>
   </game>

   <game status="pending">
      <Home_Team>C</Home_Team>
      <Away_Team>D</Away_Team>
      <Date>2013-07-27</Date>
      <Home_Team_Score>0</Home_Team_Score>
      <Away_Team_Score>0</Away_Team_Score>
   </game>
</Schedule>

Here is my xsl code:

 <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:key name="TeamByName" match="Home_Team|Away_Team" use="."/>
      <xsl:template match="/*">
       <html>
          <body>
     <table border="1">
      <tr>
       <td>Team</td>
       <td>Wins</td>
       <td>Losses</td>
       <td>Tie</td>
      </tr>
      <xsl:for-each select="//game[@status='played']">
      <xsl:apply-templates select="(*/Home_Team | */Away_Team)[generate- id()=generate-  id(key('TeamByName', .)[1])]">
    <xsl:sort select="."/>
<     /xsl:apply-templates>
      </table>
      </body>
      </html>
     </xsl:template> 

      <xsl:template match="Home_Team|Away_Team">
      <tr>
       <td>
        <xsl:value-of select="."/>
       </td>
       <td>

        <xsl:value-of select=
        "count(key('TeamByName', .)
                     [self::Home_Team
                    and
                      ../Home_Team_Score > ../Away_Team_Score 
                    or
                      self::Away_Team
                    and
                      ../Away_Team_Score > ../Home_Team_Score
                     ]
                 )"/>

       </td>
       <td>

        <xsl:value-of select= "count(key('TeamByName', .)
                     [self::Home_Team
                    and
                      ../Away_Team_Score > ../Home_Team_Score
                    or
                      self::Away_Team
                    and
                      ../Home_Team_Score > ../Away_Team_Score
                     ]
                 )"/>

       </td>
       <td>

        <xsl:value-of select="count(key('TeamByName', .)
                     [../Home_Team_Score = ../Away_Team_Score]
                 )"/>

       </td>
      </tr>
     </xsl:template>
    </xsl:stylesheet>

Output should like in the form of:

<table border="1">
   <tr>
      <td>Team</td>
      <td>Wins</td>
      <td>Losses</td>
      <td>Ties</td>
   </tr>
   <tr>
      <td>A</td>
      <td>1</td>
      <td>0</td>
      <td>2</td>
   </tr>
   <tr>
      <td>B</td>
      <td>0</td>
      <td>0</td>
      <td>1</td>
   </tr>
   <tr>
      <td>C</td>
      <td>0</td>
      <td>2</td>
      <td>1</td>
   </tr>
   <tr>
      <td>D</td>
      <td>1</td>
      <td>0</td>
      <td>0</td>
   </tr>
</table>
  • What is your output ? Can't immediately see any problem. Your select="//game[@status='played']" ought to work – peter.murray.rust Aug 07 '13 at 21:05
  • what is your actual output - and what is the actual problem? – peter.murray.rust Aug 08 '13 at 14:56
  • @peter The output should be in a table that has team names and their standings wins, losses and ties.When is applied I'm not getting out whereas when the condition is not applied I'm getting output for both status(played and pending).I want just the game stadings that are played only. – Sireesha Arum Aug 08 '13 at 15:02

0 Answers0