XSLT follow-sibling没有返回值

时间:2013-04-26 03:30:11

标签: xslt xslt-1.0

我正在努力为足球联赛创建一个积分榜。我是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 个答案:

答案 0 :(得分: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>