遇到一些困难让我的列表通过javascript显示

时间:2014-03-01 11:10:13

标签: javascript xml xslt

我有schedule.xml,其中包含所有游戏。我有一个Transform(battyleague.xsl)。然后是Javascript文件(library.js)。

我可以获得Wins,Loss,Ties,然后按Wins排序显示。但我还需要有一个下拉列表,显示个人的团队游戏日期,游戏的home_team,游戏的away_team以及游戏的状态。

我一直在环顾四周,并尝试了一些解决方案,但是我无法获得我想要使用的解决方案。代码甚至没有显示简单的HTML选择下拉列表,我无法弄清楚原因。

我的XML:

<?xml-stylesheet type="text/xsl" href="battyleague1.xsl" ?>
<Schedule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schedule.xsd" season="2013" >
    <Teams>
       <Team>Bluejays</Team>
    </Teams>
    <Teams>
       <Team>Mavericks</Team>
    </Teams>

     <Game status="Played">
       <Home_Team>Mavericks</Home_Team>
       <Away_Team>Bluejays</Away_Team>
       <Home_Team_Score>5</Home_Team_Score>
       <Away_Team_Score>3</Away_Team_Score>
       <Date>2014-03-12T09:00:00</Date>
     </Game>

      <Game status="Pending">
        <Home_Team>Bluejays</Home_Team>
        <Away_Team>Mavericks</Away_Team>
        <Home_Team_Score>0</Home_Team_Score>
        <Away_Team_Score>0</Away_Team_Score>
        <Date>2014-03-12T09:00:00</Date>
      </Game>
</Schedule>

我的XSL:                   

  <xsl:template match="/Schedule">
    <html>

      <head>
        <link href="batty.css" rel="stylesheet" type="text/css"/>
      </head>
      <body>
        <xsl:apply-templates />
        <xsl:call-template name="rankings"/>
        <script type="text/javascript" src="JScript.js"></script>
        <center>
          Select team name to see its schedule :
          <select id="team_name" onchange="notify();">
            <option value="none">--Select--</option>
            <option value="Bluejays">Bluejays</option>
            <option value="Huskers">Huskers</option>
            <option value="Mavericks">Mavericks</option>
            <option value="Lancers">Lancers</option>
            <option value="Stars">Stars</option>
            <option value="Storm">Storm</option>
          </select>

          <table border="0" id="tblBluejays" style="Display:none;">
            <caption>
              <b>Team Bluejays' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Bluejays' or Away_Team='Bluejays'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>

          <table border="0" id="tblHuskers" style="Display:none;">
            <caption>
              <b>Team Huskers' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Huskers' or Away_Team='Huskers'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>

          <table border="0" id="tblMavericks" style="Display:none;">
            <caption>
              <b>Team Mavericks' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Mavericks' or Away_Team='Mavericks'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>

          <table border="0" id="tblLancers" style="Display:none;">
            <caption>
              <b>Team Lancers' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Lancers' or Away_Team='Lancers'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>

          <table border="0" id="tblStars" style="Display:none;">
            <caption>
              <b>Team Stars' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Stars' or Away_Team='Stars'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>

          <table border="0" id="tblStorm" style="Display:none;">
            <caption>
              <b>Team Storm' Schedule</b>
            </caption>
            <tr>
              <th bgcolor="#A4A4A4">Date</th>
              <th bgcolor="#A4A4A4">Home Team</th>
              <th bgcolor="#A4A4A4">Away Team</th>
              <th bgcolor="#A4A4A4">Status</th>
            </tr>
            <xsl:for-each select="/Schedule/Game">
              <xsl:if test="Home_Team='Storm' or Away_Team='Storm'">
                <tr>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Date"/>
                  </td>
                  <td align="center" bgcolor="#FF6600">
                    <xsl:value-of select="Home_Team"/>
                  </td>
                  <td align="center" bgcolor="#2E9AFE">
                    <xsl:value-of select="Away_Team"/>
                  </td>
                  <td align="center" bgcolor="#BFFF00">
                    <xsl:value-of select="Status"/>
                  </td>
                </tr>
              </xsl:if>
            </xsl:for-each>
          </table>
        </center>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="rankings">
    <table cellspacing="1" cellpadding="2" id="scores">
      <tr class="title">
        <th colspan="22">
          Season <xsl:value-of select="//Schedule/@season"/>
        </th>
      </tr>

      <tr class="fields">
        <th style="text-align: left">Team</th>
        <th>Wins</th>
        <th>Losses</th>
        <th>Ties</th>

      </tr>


    </table>
  </xsl:template>

  <xsl:template match="Team">

    <xsl:for-each select="Game">

           <xsl:sort select="count(//Game[@Status='Played'][Home_Team=current()][Home_Team_Score &gt; Away_Team_Score]) + count(//Game[@Status='Played'][Away_Team=current()][Away_Team_Score &gt; Home_Team_Score])" data-type="number" order="ascending"/>

      <tr class="rankingTeams">
      <td style="text-align: left">




      </td>
      <td>

        <xsl:value-of select="count(//Game[@Status='Played'][Home_Team=current()][Home_Team_Score &gt; Away_Team_Score]) 
            + count(//Game[@Status='Played'][Away_Team=current()][Away_Team_Score &gt; Home_Team_Score])"/>



      </td>
      <td>
                <xsl:value-of select="count(//Game[@Status='Played'][Home_Team=current()][Home_Team_Score &lt; Away_Team_Score]) 
            + count(//Game[@Status='Played'][Away_Team=current()][Away_Team_Score &lt; Home_Team_Score])"/>

      </td>
      <td>
                <xsl:value-of select="count(//Game[@Status='Played'][Home_Team=current()][Home_Team_Score = Away_Team_Score])"/>
      </td>

    </tr>
    </xsl:for-each>
  </xsl:template>
  <xsl:param name="teamId" />
  <xsl:template match="Teams">
    <h1>
      <xsl:for-each select="/Schedule/Game">
        <xsl:if test="Home_Team=Team[$teamId] or Away_Team=Team[$teamId]">
          <tr>
            <td align="center">
              <xsl:value-of select="Date"/>
            </td>
            <td align="center">
              <xsl:value-of select="Home_Team"/>
            </td>
            <td align="center">
              <xsl:value-of select="Away_Team"/>
            </td>
            <td align="center">
              <xsl:value-of select="Status"/>
            </td>
          </tr>
        </xsl:if> 
      </xsl:for-each>

    </h1>
  </xsl:template>
  <xsl:template match="Game">

  </xsl:template>

</xsl:stylesheet>

我的javascript文件:

function notify() {

    // get value of selected team
    var e = document.getElementById("team_name");
    var team = e.options[e.selectedIndex].value;
    ShowSchedule(team);

    //alert(team);
}

function ShowSchedule(team) {

    var tblBluejays = document.getElementById('tblBluejays');
    var tblHuskers = document.getElementById('tblHuskers');
    var tblLancers = document.getElementById('tblLancers');
    var tblMavericks = document.getElementById('tblMavericks');
    var tblStars = document.getElementById('tblStars');
    var tblStorm = document.getElementById('tblStorm');

    switch (team) {
        case 'Bluejays':

            tblBluejays.style.display = "block";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "none";
            tblStars.style.display = "none";
            tblStorm.style.display = "none";
            break;
        case 'Huskers':

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "block";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "none";
            tblStars.style.display = "none";
            tblStorm.style.display = "none";
            break;
        case 'Lancers':

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "block";
            tblMavericks.style.display = "none";
            tblStars.style.display = "none";
            tblStorm.style.display = "none";
            break;
        case 'Mavericks':

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "block";
            tblStars.style.display = "none";
            tblStorm.style.display = "none";
            break;
        case 'Stars':

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "none";
            tblStars.style.display = "block";
            tblStorm.style.display = "none";
            break;
        case 'Storm':

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "none";
            tblStars.style.display = "none";
            tblStorm.style.display = "block";
            break;
        default:

            tblBluejays.style.display = "none";
            tblHuskers.style.display = "none";
            tblLancers.style.display = "none";
            tblMavericks.style.display = "none";
            tblStars.style.display = "none";
            tblStorm.style.display = "none";
    }
}

同样,我想要实现的只是一个下拉列表,列出了特定团队所有或正在等待的所有游戏;显示以下列:

                        Team Select = Mavericks
  Status   Date                 Home_Team          Away_Team
  Played   2014-03-12T09:00:00  Mavericks          Bluejays
  Pending  2014-03-12T09:00:00  Bluejays           Mavericks

谢谢, Gremmik82

0 个答案:

没有答案