我有一张包含以下格式的游戏的表格:
ID | GameName | EasyLevels | HardLevels | TotalLevels
1 Stakeboard 32 28 60
....
此表由xslt文件生成,该文件包含:
<xsl:for-each select="//games">
<tr>
<th>GameID</th>
<th>GameName</th>
<th>EasyLevels</th>
<th>HardLevels</th>
<th>TotalLevels</th>
</tr>
<xsl:for-each select="game">
<tr>
<td><xsl:value-of select="GameId"/></td>
<td><xsl:value-of select="GameName"/></td>
<td><xsl:value-of select="count(levels/level[leveldifficult='Easy'])"/></td>
<td><xsl:value-of select="count(levels/level[leveldifficult='Hard'])"/></td>
<td><xsl:value-of select="count(levels/level)"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
我还有2个按钮xslt文件。因为我希望能够在单击按钮时按每个级别的数量对表进行排序。但我不知道如何在xslt中这样做。你知道这有可能吗?
<button>Order By Number Of EasyLevels</button>
<button>Order By Number Of HardLevels</button>
xml是这样的:
<games>
<game>
<GameId>1</GameID>
<GameName>Game Title</GameName>
<levels>
<level>
<environment>City</environment>
<music>city_40</music>
<difficult>easy</difficult>
</level>
<level>
....
</level>
....
</levels>
</game>
´
<game>
<GameId>2</GameID>
<GameName>Game Title 2</GameName>
<levels>
<level>
<environment>forest</environment>
<music>forest_100</music>
<difficult>hard</difficult>
</level>
<level>
....
</level>
....
</levels>
</game>
</games>
答案 0 :(得分:1)
tl dr:您可能正在寻找sort功能
XSLT 已经有一个排序功能,可根据定义的标准对信息进行排序
<xsl:sort
select = string-expression
lang = { nmtoken }
data-type = { "text" | "number" | QName }
order = { "ascending" | "descending" }
case-order = { "upper-first" | "lower-first" }
</xsl:sort>
属性: