我是XSLT的新手,所以请原谅我的无知。我需要从XML文件格式化足球排名并创建HTML表格。除了一件事,我能做我需要做的所有事情。我需要在每个区域上面创建一个表格行,我找不到这样做的方法。
这是我的XML文件:
<?xml version="1.0" encoding="UTF-8" ?>
<Result>
<Standings>
<Division Name="Region 1A">
<Team Name="Bogue Chitto" City="Bogue Chitto" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="185" PointsAgainst="93" LeagueWins="2" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="95" LeaguePointsAgainst="56" />
<Team Name="St. Joseph" City="Greenville" State="MS" IsMemberSchool="Yes" League="1A Region 2" Wins="3" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="126" PointsAgainst="62" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="37" LeaguePointsAgainst="26" />
<Team Name="Stringer" City="Stringer" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="3" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="137" PointsAgainst="61" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="28" LeaguePointsAgainst="14" />
<Team Name="Durant" City="Durant" State="MS" IsMemberSchool="Yes" League="1A Region 2" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="77" PointsAgainst="84" LeagueWins="0" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="6" LeaguePointsAgainst="36" />
<Team Name="Cathedral" City="Natchez" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="158" PointsAgainst="142" LeagueWins="1" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.500" LeaguePointsFor="88" LeaguePointsAgainst="81" />
<Team Name="Smithville" City="Smithville" State="MS" IsMemberSchool="Yes" League="1A Region 1" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="99" PointsAgainst="60" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="22" LeaguePointsAgainst="7" />
<Team Name="Salem" City="Tylertown" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="80" PointsAgainst="40" LeagueWins="1" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.500" LeaguePointsFor="40" LeaguePointsAgainst="40" />
<Team Name="Sacred Heart" City="Hattiesburg" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="68" PointsAgainst="54" LeagueWins="0" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="20" LeaguePointsAgainst="34" />
<Team Name="Thrasher" City="Booneville" State="MS" IsMemberSchool="Yes" League="1A Region 1" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="19" PointsAgainst="22" LeagueWins="0" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="7" LeaguePointsAgainst="22" />
<Team Name="Broad Street" City="Shelby" State="MS" IsMemberSchool="Yes" League="1A Region 2" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="62" PointsAgainst="84" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="22" LeaguePointsAgainst="14" />
<Team Name="Dexter" City="Tylertown" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="62" PointsAgainst="74" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="34" LeaguePointsAgainst="20" />
<Team Name="Pelahatchie" City="Pelahatchie" State="MS" IsMemberSchool="Yes" League="1A Region 3" Wins="2" Losses="1" Ties="0" WinningPercentage="0.667" PointsFor="124" PointsAgainst="78" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="47" LeaguePointsAgainst="13" />
<Team Name="Hamilton" City="Hamilton" State="MS" IsMemberSchool="Yes" League="1A Region 1" Wins="3" Losses="2" Ties="0" WinningPercentage="0.600" PointsFor="117" PointsAgainst="92" LeagueWins="1" LeagueLosses="1" LeagueTies="0" LeagueWinningPercentage="0.500" LeaguePointsFor="58" LeaguePointsAgainst="39" />
<Team Name="Falkner" City="Falkner" State="MS" IsMemberSchool="Yes" League="1A Region 1" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="137" PointsAgainst="148" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="32" LeaguePointsAgainst="27" />
<Team Name="Noxapater" City="Noxapater" State="MS" IsMemberSchool="Yes" League="1A Region 3" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="89" PointsAgainst="73" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="20" LeaguePointsAgainst="13" />
<Team Name="Nanih Waiya" City="Louisville" State="MS" IsMemberSchool="Yes" League="1A Region 3" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="113" PointsAgainst="88" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="47" LeaguePointsAgainst="13" />
<Team Name="Shaw" City="Shaw" State="MS" IsMemberSchool="Yes" League="1A Region 2" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="77" PointsAgainst="64" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="36" LeaguePointsAgainst="6" />
<Team Name="Sebastopol" City="Sebastopol" State="MS" IsMemberSchool="Yes" League="1A Region 3" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="128" PointsAgainst="112" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="47" LeaguePointsAgainst="0" />
<Team Name="St. Aloysius" City="Vicksburg" State="MS" IsMemberSchool="Yes" League="1A Region 2" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="88" PointsAgainst="65" LeagueWins="1" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="1.000" LeaguePointsFor="48" LeaguePointsAgainst="20" />
<Team Name="Resurrection Catholic" City="Pascagoula" State="MS" IsMemberSchool="Yes" League="1A Region 4" Wins="2" Losses="2" Ties="0" WinningPercentage="0.500" PointsFor="123" PointsAgainst="66" LeagueWins="0" LeagueLosses="2" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="46" LeaguePointsAgainst="66" />
</Division>
<Division Name="Region 2A">
<Team Name="Byers" City="Holly Springs" State="MS" IsMemberSchool="Yes" League="2A Region 2" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="144" PointsAgainst="58" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Bassfield" City="Bassfield" State="MS" IsMemberSchool="Yes" League="2A Region 7" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="154" PointsAgainst="47" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="East Webster" City="Maben" State="MS" IsMemberSchool="Yes" League="2A Region 4" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="129" PointsAgainst="65" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Richton" City="Richton" State="MS" IsMemberSchool="Yes" League="2A Region 8" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="129" PointsAgainst="53" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Lake" City="Lake" State="MS" IsMemberSchool="Yes" League="2A Region 5" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="184" PointsAgainst="42" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Eupora" City="Eupora" State="MS" IsMemberSchool="Yes" League="2A Region 4" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="176" PointsAgainst="49" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="East Union" City="Blue Springs" State="MS" IsMemberSchool="Yes" League="2A Region 1" Wins="4" Losses="0" Ties="0" WinningPercentage="1.000" PointsFor="118" PointsAgainst="56" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Bruce" City="Bruce" State="MS" IsMemberSchool="Yes" League="2A Region 4" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="100" PointsAgainst="63" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Walnut" City="Walnut" State="MS" IsMemberSchool="Yes" League="2A Region 1" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="128" PointsAgainst="102" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Leland" City="Leland" State="MS" IsMemberSchool="Yes" League="2A Region 3" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="93" PointsAgainst="68" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Mize" City="Mize" State="MS" IsMemberSchool="Yes" League="2A Region 8" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="125" PointsAgainst="96" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Taylorsville" City="Taylorsville" State="MS" IsMemberSchool="Yes" League="2A Region 8" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="101" PointsAgainst="35" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Mantachie" City="Mantachie" State="MS" IsMemberSchool="Yes" League="2A Region 1" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="158" PointsAgainst="110" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="East Marion" City="Columbia" State="MS" IsMemberSchool="Yes" League="2A Region 7" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="75" PointsAgainst="60" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
<Team Name="Calhoun City" City="Calhoun City" State="MS" IsMemberSchool="Yes" League="2A Region 4" Wins="3" Losses="1" Ties="0" WinningPercentage="0.750" PointsFor="109" PointsAgainst="71" LeagueWins="0" LeagueLosses="0" LeagueTies="0" LeagueWinningPercentage="0.000" LeaguePointsFor="0" LeaguePointsAgainst="0" />
</Division>
</Standings>
</Result>
这是我目前的XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Result">
<html>
<body>
<h2>Standings</h2>
<table border="1">
<tr bgcolor="#C0C0C0">
<th>Team</th>
<th>Region</th>
<th>Div. W</th>
<th>Div. L</th>
<th>Div. T</th>
<th>Div. Pct.</th>
<th>Wins</th>
<th>Losses</th>
<th>Ties</th>
<th>Pct.</th>
<th>PF</th>
<th>PA</th>
</tr>
<xsl:for-each select="Standings/Division">
<tr align="center">
<td colspan="12" bgcolor="#D3D3D3">Class <xsl:value-of select='substring(@Name,7,3)'/></td>
</tr>
<tr align="center"><td colspan="12" bgcolor="#D3D3D3">Region 1</td></tr>
<xsl:for-each select="./Team">
<xsl:sort select="@League"/>
<xsl:sort select="@LeagueWinningPercentage" order="descending"/>
<xsl:sort select="@LeagueWins" order="descending"/>
<xsl:sort select="@WinningPercentage" order="descending"/>
<xsl:sort select="@Wins" order="descending"/>
<xsl:sort select="@Name" order="ascending"/>
<tr>
<td><xsl:value-of select="@Name"/></td>
<td><xsl:value-of select='substring(@League,4,9)'/></td>
<td><xsl:value-of select="@LeagueWins"/></td>
<td><xsl:value-of select="@LeagueLosses"/></td>
<td><xsl:value-of select="@LeagueTies"/></td>
<td><xsl:value-of select="@LeagueWinningPercentage"/></td>
<td><xsl:value-of select="@Wins"/></td>
<td><xsl:value-of select="@Losses"/></td>
<td><xsl:value-of select="@Ties"/></td>
<td><xsl:value-of select="@WinningPercentage"/></td>
<td><xsl:value-of select="@PointsFor"/></td>
<td><xsl:value-of select="@PointsAgainst"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
最终输出应如下所示:
答案 0 :(得分:0)
您的代码运行良好,只需稍作修改即可使区域标题正常工作:
使用以下语句替换XSLT中的硬编码“Region 1”字符串:
<xsl:value-of select="@Name"/>
这将在您已经为区域信息正确格式化的行中创建“区域1”,“区域2”等。您的代码实际上已从Description/@Name
拉出表格的Region列。你需要改变一些不同的东西吗?