Kurt Abele
Kurt Abele

Reputation: 37

XSLT following-sibling not returning values

I am trying to create a standings board for a soccer league. I am very new to XSLT and blundering my way around.

Below is the data format that I have

Data:

<sports-statistics>
  <sports-team-stats>
    <date year="2013" month="4" date="23" day="2"/>
    <time hour="16" minute="00" second="59" timezone="Eastern" utc-hour="-4" utc-minute="00"/>
    <version number="2"/>
    <league global-id="513" name="Youth Soccer League" alias="YSL" display-name=""/>
    <season year="2013" id="1" description="2013 YSL Season"/>
     <soccer-ifb-team-stats>
      <ifb-team>
         <team-info global-id="11270" id="1869" location="Tulsa" name="Astecs" alias="TUL" display-name="Astecs"/>
         <split id="0" type="all" name="All Games">
           <games-played games="1"/>
           <record wins="0" losses="0" ties="1" percentage=".500"/>
           <minutes minutes="90"/>
           <goals goals="1" headed="0" kicked="1" />
           <opponent-goals goals="1"/>
           <own-goals goals="0"/>
           <assists assists="1"/>
           <opponent-assists assists="1"/>
           <shots shots="18"/>
           <opponent-shots shots="10"/>
           <shots-on-goal shots="7"/>
           <opponent-shots-on-goal shots="4"/>
         </split>
         <split id="302" type="home" name="Home Games">
           <games-played games="1"/>
           <record wins="0" losses="0" ties="1" percentage=".500"/>
           <minutes minutes="90"/>
           <goals goals="1" headed="0" kicked="1" />
           <opponent-goals goals="1"/>
           <own-goals goals="0"/>
           <assists assists="1"/>
           <opponent-assists assists="1"/>
           <shots shots="18"/>
           <opponent-shots shots="10"/>
           <shots-on-goal shots="7"/>
           <opponent-shots-on-goal shots="4"/>
         </split>
      </ifb-team>
     </soccer-ifb-team-stats>
    </sports-team-stats>
</sports-statistics>

Here is my code so far.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes"  encoding = "utf-8"   standalone = "yes"/>

  <xsl:variable name="allGames">
    <map gametype="All Games" />
  </xsl:variable>
  <xsl:variable name="gameMapping" select="msxsl:node-set($allGames)/*" />

  <xsl:template match="/">

    <html>
        <head>
        <meta charset="utf-8" />
        <title> Standings</title>
      </head>

      <body>
        <h2>  TEST </h2>

        <table  border="1" style="width: 100%;">
          <tr>
            <th>Club</th>           
            <th>GP</th> <!--Games Played-->
            <th>W</th> <!--Wins-->
            <th>L</th> <!--Loss-->
            <th>T</th> <!--Ties-->
            <th>%</th> <!--Win Loss Ratio-->
          </tr>

           <xsl:apply-templates select="//ifb-team/split[@name = 'All Games']" />

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

  <xsl:template match="ifb-team/split">
    <xsl:variable name="ti" select="../team-info" />
    <tr>
      <td>
        <xsl:value-of select="$ti/@display-name" />
      </td>
      <td>
        <xsl:value-of select="following-sibling::games-played/@games"/>
      </td>
      <td>
        <xsl:value-of select="following-sibling::record/@wins"/>
      </td>
      <td>
        <xsl:value-of select="following-sibling::record/@losses"/>
       </td>
      <td>
        <xsl:value-of select="following-sibling::record/@ties"/>
      </td>
      <td>
        <xsl:value-of select="following-sibling::record/@percentage"/>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

All I am getting is a table with the display name and nothing else. I am not getting any of the siblings data. What am I missing?

Upvotes: 1

Views: 123

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243619

This is simple:

games-played is not a sibling -- it is a child of split.

The same is true for record.

Therefore, use:

  <td>
    <xsl:value-of select="games-played/@games"/>
  </td>
  <td>
    <xsl:value-of select="record/@wins"/>
  </td>
  <td>
    <xsl:value-of select="record/@losses"/>
   </td>
  <td>
    <xsl:value-of select="record/@ties"/>
  </td>
  <td>
    <xsl:value-of select="record/@percentage"/>
  </td>

Upvotes: 1

Related Questions