|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XML/XSL for-each
I'm trying to learn xml/xsl by example and I've created a annoying little problem for my self.
I'm trying to print multiple systems for each games but everything I've tried with an embeded for-each in each game doesn't produce anything. The problem with the xml below is that I can only get the first system elemnt to be shown. <game> <role_playing> <name>Chrono Trigger</name> <rating>4</rating> <maker>Squaresoft</maker> <system>Super Nintendo</system> <system>Playstation</system> </role_playing> </game> Here is the dtd i'm using: <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT game (role_playing)+> <!ELEMENT role_playing (name?, rating?, maker?, system+)> <!ELEMENT name (#PCDATA)> <!ELEMENT rating (#PCDATA)> <!ELEMENT maker (#PCDATA)> <!ELEMENT system (#PCDATA)> And here is a piece of the xsl: <xsl:for-each select="game/role_playing"> <xsl:sort select="name"/> <xsl:value-of select="name"/> <xsl:choose> <xsl:when test="rating = 5"> §§§§§</xsl:when> <xsl:when test="rating = 4"> §§§§</xsl:when> <xsl:when test="rating = 3"> §§§</xsl:when> <xsl:when test="rating = 2"> §§</xsl:when> <xsl:when test="rating = 1"> §</xsl:when> <xsl:otherwise> No rating given</xsl:otherwise> </xsl:choose> <xsl:value-of select="maker"/> The game can be found on the following system(s):<xsl:value-of select="system"/>) </xsl:for-each> What is the best way to print the multiple systems? |
|
#2
|
||||
|
||||
|
Seems to me you would need another for-each loop, to display all the system(s) for each game.
__________________
Hello, old friend... |
|
#3
|
|||
|
|||
|
Here is another way of achieving what you what. For
brevity I dropped the sort. <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template match="game/role_playing"> <xsl:choose> <xsl:when test="rating = 5"> XXXXX </xsl:when> <xsl:when test="rating = 4"> XXXX </xsl:when> <xsl:when test="rating = 3"> XXX </xsl:when> <xsl:when test="rating = 2"> XX </xsl:when> <xsl:when test="rating = 1"> X </xsl:when> <xsl:otherwise> No rating given</xsl:otherwise> </xsl:choose> <xsl:value-of select = "maker" /> The game can be found on the following system(s): <xsl:copy-of select="./system/text()" /> </xsl:template> </xsl:stylesheet> |
|
#4
|
|||
|
|||
|
Thanks murphy
I just added the text() method to all the examples i created before and it all worked. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML/XSL for-each |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|