【发布时间】:2014-04-03 01:01:21
【问题描述】:
我想通过我的 XML 文件使用 XSL 创建一个循环,该循环仅处理评分高于 5 的游戏:
<game_id id="101">
<game_name>Minecraft</game_name>
<game_price currency="€">23.99</game_price>
<game_type type="Sandbox" />
<game_art>minecraft.jpg</game_art>
<game_platform>
<platform platform="XboxOne">XboxOne</platform>
<platform platform="Ps4">Ps4</platform>
<platform platform="PC">PC</platform>
<platform platform="Mac">Mac</platform>
</game_platform>
<game_desc>Simple block based game</game_desc>
<game_dev>Mojang</game_dev>
<game_rating rating="9">5/10 </game_rating>
<game_review>
<para para="1">The game involves players creating and destroying various types of blocks in a three dimensional environment.
The player takes an avatar that can destroy or create blocks, forming fantastic structures,
creations and artwork across the various multiplayer servers in multiple game modes
</para>
<para para="x"></para>
<para para="x"></para>
</game_review>
</game_id>
我一直在尝试创建循环,但我的尝试失败了:
<xsl:choose>
<xsl:when test="game_id/game_rating = '5'">
<h1><xsl:value-of select="game_name"></xsl:value-of></h1>
<hr />
<img> <xsl:attribute name="src"> <xsl:value-of select="game_art"/></xsl:attribute></img>
<p><strong>Price:</strong> <xsl:value-of select="game_price"></xsl:value-of></p>
<xsl:for-each select="game_platform/platform">
<p><strong>Platform:</strong> <xsl:value-of select="node()"></xsl:value-of></p>
</xsl:for-each>
<p><strong>Game Desc: </strong> <xsl:value-of select="game_desc"></xsl:value-of></p>
<p><strong>Game Dev: </strong> <xsl:value-of select="game_dev"></xsl:value-of></p>
<p><strong>Game Rating: </strong> <xsl:value-of select="game_rating"></xsl:value-of></p>
<h4>Game Reveiw</h4>
<xsl:for-each select="game_review/para">
<p><xsl:value-of select="node()"></xsl:value-of></p>
</xsl:for-each>
</xsl:when>
</xsl:choose>
任何帮助将不胜感激。
【问题讨论】:
-
不需要循环(也不可取):使用 谓词 代替。
-
我不理解你的 XML:
<game_rating rating="9">5/10 </game_rating>- 评级是9还是5/10? -
如果要循环,请使用 BASIC 中的 FOR 语句。