2013-04-26 35 views
1

我想創建一個足球聯賽的積分榜。我對XSLT非常陌生,並且錯過了我的方式。XSLT下面的兄弟姐妹沒有返回值

下面是數據格式,我有

數據:

<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> 

這裏是我到目前爲止的代碼。

<?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> 

我所得到的只是一個帶有顯示名稱而沒有別的表格。我沒有得到任何兄弟姐妹的數據。我錯過了什麼?

回答

1

這是簡單

games-played是不是兄弟 - 這是一個孩子的split

對於record也是如此。

因此,使用

<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> 
+0

OMG謝謝....我想我需要回去XPath和做一些更多的學習! – 2013-04-27 12:34:28

+0

@KurtAbele,當然 - XPath是XSLT和XQuery的核心。 – 2013-04-27 15:05:51