XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2004, 03:01 PM
vehemon vehemon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 vehemon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old February 19th, 2004, 04:05 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
Seems to me you would need another for-each loop, to display all the system(s) for each game.
__________________
Hello, old friend...

Reply With Quote
  #3  
Old February 19th, 2004, 07:11 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 285 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 6 m 53 sec
Reputation Power: 6
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>

Reply With Quote
  #4  
Old February 20th, 2004, 01:24 PM
vehemon vehemon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 vehemon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Thanks murphy

I just added the text() method to all the examples i created before and it all worked.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML/XSL for-each


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT