无法在XSL中为代码评级添加颜色

时间:2016-11-30 10:08:48

标签: xml xslt

我一直试图解决此问题,但无法对收视率进行颜色编码。我们应该为G,PG,M,MA 15+和R 18+提供不同的颜色。 这是我的XML和XSL; XML

`<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xboxgames.xsl"?>
<!DOCTYPE xbox_games [
    <!ELEMENT xbox_games (game+)>
    <!ELEMENT game (title,platform,developer,publisher,composer,release_date,rating,engine,game_modes)>
    <!ELEMENT title (#PCDATA)>
    <!ELEMENT platform (#PCDATA)>
    <!ELEMENT developer (#PCDATA)>
    <!ELEMENT publisher (#PCDATA)>
    <!ELEMENT composer (#PCDATA)>
    <!ELEMENT release_date (#PCDATA)>
    <!ELEMENT rating (#PCDATA)>
    <!ELEMENT engine (#PCDATA)>
    <!ELEMENT game_modes (#PCDATA)>

]>

<xbox_games>
    <game>
        <title>Aliens Colonial Marines</title>
        <platform>xbox 360</platform>
        <developer>Gearbox Software</developer>
        <publisher>Sega</publisher>
        <composer>Kevin Riepl</composer>
        <release_date>12th February 2013</release_date>
        <rating>MA 15+</rating>
        <engine>Red Ring</engine>
        <game_modes>Single-player Multiplayer</game_modes>
    </game>
    <game>
        <title>Assassins Creed IV Black Flag</title>
        <platform>Xbox One</platform>
        <developer>Ubisoft Montreal</developer>
        <publisher>Ubisoft</publisher>
        <composer>Brian Tyler</composer>
        <release_date>29th October 2013</release_date>
        <rating>MA 15+</rating>
        <engine>AnvilNext</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Defiance</title>
        <platform>Xbox 360</platform>
        <developer>Trion Worlds and Human Head Studio</developer>
        <publisher>Trion Worlds</publisher>
        <composer>Unnamed</composer>
        <release_date>2nd April 2013</release_date>
        <rating>MA 15+</rating>
        <engine>Unnamed</engine>
        <game_modes>Multiplayer</game_modes>
    </game>
    <game>
        <title>Grand Theft Auto V</title>
        <platform>Xbox 360</platform>
        <developer>Rockstar North</developer>
        <publisher>Rockstar Games</publisher>
        <composer>Tangerine Dream, Woody Jackson, The Alchemist, Oh No</composer>
        <release_date>17th September 2013</release_date>
        <rating>R 18+</rating>
        <engine>RAGE with Euphoria and Bullet Physics</engine>
        <game_modes>Single-player, Online Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo 3 ODST</title>
        <platform>Xbox 360</platform>
        <developer>Bungie</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Martin O'Donnell, Michael Salvatori</composer>
        <release_date>22nd September 2009</release_date>
        <rating>M</rating>
        <engine>Halo Engine</engine>
        <game_modes>Single-player, Co-op, Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo 3</title>
        <platform>Xbox 360</platform>
        <developer>Bungie</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Martin O'Donnell, Michael Salvatori</composer>
        <release_date>25th September 2007</release_date>
        <rating>M</rating>
        <engine>Halo Engine</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo 4</title>
        <platform>Xbox 360</platform>
        <developer>343 Industries</developer>
        <publisher>Microsoft Studios</publisher>
        <composer>Neil Davidge, Kazuma Jinnouchi</composer>
        <release_date>6th November 2012</release_date>
        <rating>M</rating>
        <engine>Halo Engine</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo Anniversary</title>
        <platform>Xbox 360</platform>
        <developer>343 Industries</developer>
        <publisher>Microsoft Studios</publisher>
        <composer>Martin O'Donnell, Michael Salvatori</composer>
        <release_date>15th November 2011</release_date>
        <rating>MA 15+</rating>
        <engine>Saber3D Engine v.S3</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo Reach</title>
        <platform>Xbox 360</platform>
        <developer>Bungie</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Martin O'Donnell, Michael Salvatori</composer>
        <release_date>14th September 2010</release_date>
        <rating>MA 15+</rating>
        <engine>Halo Engine</engine>
        <game_modes>Single-player, Co-op, Multiplayer</game_modes>
    </game>
    <game>
        <title>Halo Spartan Assault</title>
        <platform>Xbox One</platform>
        <developer>343 Industries, Vanguard Entertainment</developer>
        <publisher>Microsoft Studios</publisher>
        <composer>Tom Salta</composer>
        <release_date>24th December 2013</release_date>
        <rating>M</rating>
        <engine>Unnamed</engine>
        <game_modes>Single-player, Co-op</game_modes>
    </game>
    <game>
        <title>Halo Wars</title>
        <platform>Xbox 360</platform>
        <developer>Ensemble Studios</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Stephen Rippy</composer>
        <release_date>26th February 2009</release_date>
        <rating>PG</rating>
        <engine>BANG! Engine</engine>
        <game_modes>Single-player</game_modes>
    </game>
    <game>
        <title>Kinect Adventures</title>
        <platform>Xbox 360</platform>
        <developer>Good Science Studio</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Unnamed</composer>
        <release_date>4th November 2010</release_date>
        <rating>PG</rating>
        <engine>Unreal 3 Engine</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Kinectimals</title>
        <platform>Xbox 360</platform>
        <developer>Frontier Developments</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Unnamed</composer>
        <release_date>4th November 2010</release_date>
        <rating>G</rating>
        <engine>Unnamed</engine>
        <game_modes>Single-player</game_modes>
    </game>
    <game>
        <title>Lightning Returns Final Fantasy XIII</title>
        <platform>Xbox 360</platform>
        <developer>Square Enix</developer>
        <publisher>Square Enix</publisher>
        <composer>Masashi Hamauzu, Naoshi Mizuta, Mitsuto Suzuki</composer>
        <release_date>11th February 2014</release_date>
        <rating>M</rating>
        <engine>Crystal Tools</engine>
        <game_modes>Single-player</game_modes>
    </game>
    <game>
        <title>Mass Effect 2</title>
        <platform>Xbox 360</platform>
        <developer>BioWare</developer>
        <publisher>Electronic Arts</publisher>
        <composer>Jack Wall</composer>
        <release_date>26th January 2010</release_date>
        <rating>MA 15+</rating>
        <engine>Unreal Engine 3</engine>
        <game_modes>Single-player</game_modes>
    </game>
    <game>
        <title>Mass</title>
        <platform>Xbox 360</platform>
        <developer>BioWare</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Jack Wall, Sam Hulick, Richard Jacques, David Kates</composer>
        <release_date>16th November 2007</release_date>
        <rating>MA 15+</rating>
        <engine>Unreal Engine 3</engine>
        <game_modes>Single-player</game_modes>
    </game>
    <game>
        <title>Rocksmith</title>
        <platform>Xbox 360</platform>
        <developer>Ubisoft San Francisco</developer>
        <publisher>Ubisoft</publisher>
        <composer>Multiple (Bands)</composer>
        <release_date>18th October 2011</release_date>
        <rating>PG</rating>
        <engine>Unnamed</engine>
        <game_modes>Unmentioned</game_modes>
    </game>
    <game>
        <title>Ryse Son of Rome</title>
        <platform>Xbox One</platform>
        <developer>Crytek Frankfurt</developer>
        <publisher>Microsoft Studios</publisher>
        <composer>Borislav Slavov, Tilman Sillescu, Peter Antovski</composer>
        <release_date>22nd November 2013</release_date>
        <rating>R 18+</rating>
        <engine>CryEngine</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Titanfall</title>
        <platform>Xbox One</platform>
        <developer>Respawn Entertainment</developer>
        <publisher>Electronic Arts</publisher>
        <composer>Stephen Barton</composer>
        <release_date>11th March 2014</release_date>
        <rating>MA 15+</rating>
        <engine>Source</engine>
        <game_modes>Online Multiplayer</game_modes>
    </game>
    <game>
        <title>Tomb Raider</title>
        <platform>Xbox One</platform>
        <developer>Crystal Dynamics</developer>
        <publisher>Square Enix</publisher>
        <composer>Jason Graves</composer>
        <release_date>5th March 2013</release_date>
        <rating>MA 15+</rating>
        <engine>Modified Crystal Engine</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Too Human</title>
        <platform>Xbox 360</platform>
        <developer>Silicon Knights</developer>
        <publisher>Microsoft Game Studios</publisher>
        <composer>Steve Henifin</composer>
        <release_date>19th August 2008</release_date>
        <rating>M</rating>
        <engine>Unreal Engine 3 Havok Physics</engine>
        <game_modes>Single-player, Multiplayer</game_modes>
    </game>
    <game>
        <title>Wolfenstein The New Order</title>
        <platform>Xbox One</platform>
        <developer>MachineGames</developer>
        <publisher>Bethesda Softworks</publisher>
        <composer>Mick Gordon</composer>
        <release_date>20th May 2014</release_date>
        <rating>R 18+</rating>
        <engine>Id Tech 5</engine>
        <game_modes>Single-player</game_modes>
    </game>
</xbox_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 List</h2>
    <table border="1">
        <tr bgcolor="#FFFFFF">
            <th>Title</th>
            <th>Platform</th>
            <th>Developer</th>
            <th>Publisher</th>
            <th>Composer</th>
            <th>Release Date</th>
            <th>Rating</th>
            <th>Engine</th>
            <th>Game Modes</th>
        </tr>
        <xsl:for-each select="xbox_games/game">
        <tr>
            <td><xsl:value-of select="title"/></td>
            <xsl:choose>
                <xsl:when test="rating &gt; G">
                    <td bgcolor="#FFA500">
                    <xsl:value-of select="rating"/></td>
                </xsl:when> 
                <xsl:when test="rating &gt; PG">
                    <td bgcolor="#00FF00">
                    <xsl:value-of select="rating"/></td>
                </xsl:when>
                <xsl:when test="rating &gt; M">
                    <td bgcolor="#AEC6CF">
                    <xsl:value-of select="rating"/></td>
                </xsl:when>
                <xsl:when test="rating &gt; MA 15+">
                    <td bgcolor="#4B0082">
                    <xsl:value-of select="rating"/></td>
                </xsl:when>
                <xsl:when test="rating &gt; R 18+">
                    <td bgcolor="#FF0000">
                    <xsl:value-of select="rating"/></td>
                </xsl:when>
                <xsl:otherwise>
                    <td><xsl:value-of select="rating"/></td>
                </xsl:otherwise>
            </xsl:choose>   
        </tr>
        </xsl:for-each>
    </table>
    </body>
    </html>
</xsl:template>

</xsl:stylesheet>   

任何帮助将不胜感激

0 个答案:

没有答案