我试图根据他们的分类以颜色突出显示我的游戏。我到处搜索,到目前为止还没有任何工作。我最近的努力涉及尝试使用。
<xsl:if test="substring(rating, string-length(rating) -3) = M">
<xsl:attribute name="style">background-color: red</xsl:attribute>
</xsl:if>
信息需要显示在表格中(覆盖范围内)然后通过评级分类突出显示。在这个阶段,我只是想让“M”级游戏以红色突出显示。
这是我的XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="styles.xsl"?>
<Games>
<game>
<title>Aliens Colonial Marines</title>
<platform>Xbox 360</platform>
<dev>Gearbox Software</dev>
<pub>Sega</pub>
<composer>Kevin Riepl</composer>
<release>Feburary 12, 2013</release>
<rating>MA 15+</rating>
<engine>Red Ring</engine>
<game_mode>Single-Player, Multiplayer</game_mode>
</game>
<game>
<title>Assasins Creed IV Black Flag </title>
<platform>Xbox 360 </platform>
<dev>:Ubisoft Montreal </dev>
<pub>Ubisoft </pub>
<composer>Brian Tyler </composer>
<release>October 29, 2013 </release>
<rating>MA 15+ </rating>
<engine>AnvilNext </engine>
<game_mode>Single-player, Multiplayer </game_mode>
</game>
<game>
<title>Defiance </title>
<platform>Xbox 360 </platform>
<dev>Trion Worlds, Human Head Studios </dev>
<pub>Trion Worlds </pub>
<composer>Unnamed </composer>
<release>April 2, 2013 </release>
<rating>MA 15+ </rating>
<engine>Unnamed </engine>
<game_mode>Multiplayer </game_mode>
</game>
<game>
<title>Grand Theft Auto V </title>
<platform>Xbox 360 </platform>
<dev>Rockstar North </dev>
<pub>Rockstar Games </pub>
<composer> Tangerine Dream, Woody Jackson, The Alchemist, Oh No </composer>
<release>September 17, 2013 </release>
<rating>R 18+ </rating>
<engine>RAGE with Euphoria and Bullet Physics </engine>
<game_mode>Single-player, Online Multiplayer </game_mode>
</game>
<game>
<title>Halo 3 ODST </title>
<platform>Xbox 360 </platform>
<dev>Bungie </dev>
<pub>Microsoft Game Studios </pub>
<composer>Martin O'Donnell, Micheal Salvatori </composer>
<release>September 22, 2009 </release>
<rating>M </rating>
<engine>Halo Engine </engine>
<game_mode>Single-player, Co-Op, Multiplayer </game_mode>
</game>
<game>
<title>Halo 3 </title>
<platform>Xbox 360 </platform>
<dev>Bungie </dev>
<pub>Microsoft Game Studios </pub>
<composer>Martin O'Donnell </composer>
<release>September 25, 2007 </release>
<rating>M </rating>
<engine>Halo Engine </engine>
<game_mode>Single Player, Multiplayer </game_mode>
</game>
<game>
<title>Halo 4 </title>
<platform>Xbox 360 </platform>
<dev>343 Industries </dev>
<pub>Microsoft Studios </pub>
<composer>Neil Davidge </composer>
<release>November 6, 2012 </release>
<rating>M </rating>
<engine>Halo Engine </engine>
<game_mode>Single-player, Multiplayer </game_mode>
</game>
<game>
<title>Halo Anniversary </title>
<platform>Xbox 360 </platform>
<dev>343 Industries </dev>
<pub>Microsoft Studios </pub>
<composer>Martin O'Donnell, Michael Salvatori </composer>
<release>November 15, 2011 </release>
<rating>MA 15+ </rating>
<engine>Saber3D Engine v.S3 </engine>
<game_mode>ingle-player, Multiplayer </game_mode>
</game>
<game>
<title>Halo Reach </title>
<platform>Xbox 360 </platform>
<dev>Bungie </dev>
<pub>Microsoft Studios </pub>
<composer>Martin O'Donnell, Michael Salvatori </composer>
<release>September 14, 2010 </release>
<rating>MA 15+ </rating>
<engine>Halo Engine </engine>
<game_mode>ingle Player, Co-Op, Mulitplayer </game_mode>
</game>
<game>
<title>Halo Spartan Assault </title>
<platform>Xbox One </platform>
<dev>343 Industries, Vanguard Entertainment </dev>
<pub>Microsoft Game Studios </pub>
<composer>Tom Salta </composer>
<release>December 24, 2013 </release>
<rating>M </rating>
<engine>Unnamed </engine>
<game_mode>Single-player, Co-Op </game_mode>
</game>
<game>
<title>Halo Wars </title>
<platform>Xbox 360 </platform>
<dev>Ensemble Studios </dev>
<pub>Microsoft Game Studios </pub>
<composer>Stephen Rippy </composer>
<release>Feburary 26, 2009 </release>
<rating>PG </rating>
<engine>BANG! Engine </engine>
<game_mode>Signle-player </game_mode>
</game>
<game>
<title>Kinect Adventures </title>
<platform>Xbox 360 </platform>
<dev>Good Science Studio </dev>
<pub>Microsoft Games Studios </pub>
<composer>Unnamed </composer>
<release>November 4, 2010 </release>
<rating>PG </rating>
<engine>Unreal 3 Engine </engine>
<game_mode>Single-player, Multiplayer </game_mode>
</game>
<game>
<title>Kinectimals </title>
<platform>Xbox 360 </platform>
<dev>Frontier Developments </dev>
<pub>Microsoft Game Studios </pub>
<composer>Unnamed </composer>
<release>November 4,2010 </release>
<rating>G </rating>
<engine>Unnamed </engine>
<game_mode>Single-player </game_mode>
</game>
<game>
<title>Lightning Returns: Final Fantasy XIII </title>
<platform> Xbox 360 </platform>
<dev>Square Enix </dev>
<pub>Square Enix </pub>
<composer>Masashi Hamauzu, Naoshi Mizuta </composer>
<release>Feburary 11, 2014 </release>
<rating>M</rating>
<engine>Crystal Tools </engine>
<game_mode>Single-player </game_mode>
</game>
<game>
<title>Mass Effect 2 </title>
<platform>Xbox 360 </platform>
<dev>BioWare </dev>
<pub>Electronic Arts </pub>
<composer>Jack Wall </composer>
<release>January 26, 2010 </release>
<rating>MA 15+ </rating>
<engine>Unreal Engine 3 </engine>
<game_mode>Single-player </game_mode>
</game>
<game>
<title>Mass Effect </title>
<platform>Xbox 360 </platform>
<dev>BioWare </dev>
<pub>Microsoft Game Studios </pub>
<composer>Jack Wall, Sam Hulick, Richard Jacques </composer>
<release>November 16, 2007 </release>
<rating>MA 15+ </rating>
<engine>Unreal Engine 3 </engine>
<game_mode>Single-player </game_mode>
</game>
<game>
<title>Rocksmith </title>
<platform> box 360 </platform>
<dev>Ubisoft San Francisco </dev>
<pub>Ubisoft </pub>
<composer>Multiple (Bands) </composer>
<release>October 18, 2011 </release>
<rating>PG </rating>
<engine>Unnamed </engine>
<game_mode>Unnamed </game_mode>
</game>
<game>
<title>Ryse, Son of Rome </title>
<platform>Xbox One </platform>
<dev>Crytek Frankfurt </dev>
<pub>Microsoft Studios </pub>
<composer>Bosiclav Slavov, Tilman Sillescu </composer>
<release>November 22, 2013 </release>
<rating>R 18+ </rating>
<engine>CryEngine </engine>
<game_mode>Single-player, Multiplayer </game_mode>
</game>
<game>
<title>Titanfall </title>
<platform>Xbox One </platform>
<dev>Respawn Entertainment </dev>
<pub>Electronic Arts </pub>
<composer>Stepehn Barton </composer>
<release>March 11, 2014 </release>
<rating>MA 15+ </rating>
<engine>Source </engine>
<game_mode>Online Multiplayer </game_mode>
</game>
<game>
<title>Tomb Raider </title>
<platform>Xbox One </platform>
<dev>Crystal Dyanmics </dev>
<pub>Square Enix </pub>
<composer>Jason Graves </composer>
<release>March 5, 2013 </release>
<rating>MA 15+ </rating>
<engine>Modified Crystal Engine </engine>
<game_mode>Single-player, Mulitplayer </game_mode>
</game>
<game>
<title>Too Human </title>
<platform>Xbox 360 </platform>
<dev>Silicon Knights </dev>
<pub>Micosoft Game Studios </pub>
<composer>Steve Henifin </composer>
<release>August 19, 2008 </release>
<rating>M </rating>
<engine>Unreal Engine 3 Havok Physics </engine>
<game_mode>Single-player, Mulitplayer </game_mode>
</game>
<game>
<title>Wolfenstein The New Order </title>
<platform>Xbox One </platform>
<dev>MachineGames </dev>
<pub>Bethesda Softwork </pub>
<composer>Mick Gordon </composer>
<release>May 20, 2014 </release>
<rating>R 18+ </rating>
<engine>id Tech 5 </engine>
<game_mode>Single-player </game_mode>
</game>
</Games>
到目前为止,这是我的XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Xbox Games Collection</h2>
<table border="1">
<tr>
<th>Title</th>
<th>Platform</th>
<th>Developer</th>
<th>Publisher</th>
<th>Composer</th>
<th>Rlease</th>
<th>Rating</th>
<th>Engine</th>
<th>Game Mode</th>
</tr>
<xsl:for-each select="Games/game">
<tr>
<xsl:if test="substring(rating, string-length(rating) -3) = M">
<xsl:attribute name="style">background-color: red</xsl:attribute>
</xsl:if>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="platform"/>
</td>
<td>
<xsl:value-of select="dev"/>
</td>
<td>
<xsl:value-of select="pub"/>
</td>
<td>
<xsl:value-of select="composer"/>
</td>
<td>
<xsl:value-of select="release"/>
</td>
<td>
<xsl:value-of select="rating"/>
</td>
<td>
<xsl:value-of select="engine"/>
</td>
<td>
<xsl:value-of select="game_mode"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
如果有人可以就如何为一个人做一些指导,我可以自己添加其他人。
提前致谢
Vriss
答案 0 :(得分:1)
您的代码存在的明显问题是它引用了一个名为M
的非现有元素,而不是字符串"M"
。
假设逻辑反映了你想要的东西(是吗?),你只需要改变:
<xsl:if test="substring(rating, string-length(rating) -3) = M">
为:
<xsl:if test="substring(rating, string-length(rating) -3) = 'M'">
在这个阶段,我只是试图让“M”级游戏突出显示 红色。
如果我不得不猜测,我会说“M”级游戏是通过此测试的游戏:
<xsl:if test="normalize-space(rating) = 'M'">
至少突出显示M
列中显示 Rating
的游戏。