我正在尝试创建一个足球联赛的积分榜。我对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>
所有我得到的是一个表与显示名称,没有别的。我没有得到任何兄弟姐妹的数据。我错过了什么?
很简单:
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>