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 April 29th, 2004, 08:34 PM
hardyrj hardyrj is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 hardyrj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XML/XSL newbie question

I am doing a simple task where I am trying to create a table of cars with co lumn headers such as model, make, color etc and then have details of the different cars underneath ..... and I have to create a dtd, xml and xls file for them. I have tried entering one set of data for a Mercedes car but the data just all comes out together on one line and doesn't create the table as I had hoped! My output looks like this:

Cars for Sale
makemodelyearcolorengineradioair conditioningpower windowspower steeringpower brakes1Mercedes BenzE2402003Black8fuel_injected yes yes yes yes yes

Any help MUCH appreciated. Thanks

Here is my code:

cars_for_sale.DTD:

<?xml version="1.0"?>

<!ELEMENT cars (car+)>
<!ELEMENT car (make, model, year, color, engine, number_of_doors, transmission_type, accessories*)>
<!ELEMENT engine (number_of_cylinders+, fuel_system)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT color (#PCDATA)>
<!ELEMENT number_of_doors (#PCDATA)>
<!ELEMENT transmission_type (#PCDATA)>
<!ELEMENT accessories (#PCDATA)>
<!ELEMENT number_of_cylinders (#PCDATA)>
<!ELEMENT fuel_system (#PCDATA)>

<!ATTLIST accessories radio CDATA #REQUIRED>
<!ATTLIST accessories air_conditioning CDATA #REQUIRED>
<!ATTLIST accessories power_windows CDATA #REQUIRED>
<!ATTLIST accessories power_steering CDATA #REQUIRED>
<!ATTLIST accessories power_brakes CDATA #REQUIRED>

<!ENTITY bmw "B M W">
<!ENTITY me "Mercedes Benz">
<!ENTITY fo "Ford">
<!ENTITY v "Volvo">
<!ENTITY mi "Mini">
<!ENTITY j "Jaguar">
<!ENTITY p "Peugeot">
<!ENTITY rr "Rolls Royce">


cars_for_sale.XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE cars_for_sale SYSTEM "cars_for_sale.dtd">

<?xml-stylesheet type="text/xsl" href="cars_for_sale.xsl"?>

<cars_for_sale>
<car id = "1">
<make>&me;</make>
<model>E240</model>
<year>2003</year>
<color>Black</color>
<engine>
<number_of_cylinders>8</number_of_cylinders>
<fuel_system>fuel_injected</fuel_system>
</engine>
<number_of_doors>5</number_of_doors>
<transmission_type>Diesel</transmission_type>
<accessories>
<radio>yes</radio>
<air_conditioning>yes</air_conditioning>
<power_windows>yes</power_windows>
<power_steering>yes</power_steering>
<power_brakes>yes</power_brakes>
</accessories>
</car>
</cars_for_sale>



cars_for_sale.XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version = "1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match = "/">

<h1>Cars for Sale</h1>
<car border = "border">
<tr>
<th></th>
<th>make</th>
<th>model</th>
<th>year</th>
<th>color</th>
<th>engine</th>
<th>radio</th>
<th>air conditioning</th>
<th>power windows</th>
<th>power steering</th>
<th>power brakes</th>
</tr>

<xsl:for-each select = "cars_for_sale/car">

<tr>
<th><xsl:value-of select = "@id" /></th>
<td><xsl:value-of select = "make" /></td>
<td><xsl:value-of select = "model" /></td>
<td><xsl:value-of select = "year"/></td>
<td><xsl:value-of select = "color"/></td>
<td><xsl:value-of select = "engine/number_of_cylinders"/></td>
<td><xsl:value-of select = "engine/fuel_system"/></td>
<td><xsl:value-of select = "accessories"/></td>
</tr>

</xsl:for-each>

</car>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #2  
Old April 30th, 2004, 12:49 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 262 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: 23 h 28 m 59 sec
Reputation Power: 6
The following should point you in the right direction

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match = "/">

<h1>Cars for Sale</h1>

<car border = "border">
<table>
<tr>
   <th></th>
   <th>make</th>
   <th>model</th>
   <th>year</th>
   <th>color</th>
   <th>engine</th>
   <th>radio</th>
   <th>air conditioning</th>
   <th>power windows</th>
   <th>power steering</th>
   <th>power brakes</th>
</tr>

<xsl:for-each select = "cars_for_sale/car">
<tr>
    <th><xsl:value-of select = "@id" /></th>
    <td><xsl:value-of select = "make" /></td>
    <td><xsl:value-of select = "model" /></td>
    <td><xsl:value-of select = "year"/></td>
    <td><xsl:value-of select = "color"/></td>
    <td><xsl:value-of select = "engine/number_of_cylinders"/></td>
    <td><xsl:value-of select = "engine/fuel_system"/></td>
    <td><xsl:value-of select = "accessories"/></td>
</tr>

</xsl:for-each>

</table>
</car>
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #3  
Old May 7th, 2004, 07:47 AM
wendra wendra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Germany
Posts: 14 wendra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well, fpmurphy was right. Anyway, try some coding with <TABLE></TABLE> tags. If you want some borders, you can add an attribute or two, like BORDER="1". If you still need any further help, don't hestitate to ask. I'd be willing to be some help.

Last edited by wendra : May 10th, 2004 at 02:11 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML/XSL newbie question


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 2 hosted by Hostway