Newbie XML/XSL question

Discussion in 'XML' started by hardyrj, Apr 30, 2004.

  1. hardyrj

    hardyrj Guest

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

    Cars for Sale
    makemodelyearcolorengineradioair conditioningpower windowspowe
    steeringpower brakes1Mercedes BenzE2402003Black8fuel_injected yes ye
    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


    -
    hardyr
    -----------------------------------------------------------------------
    Posted via http://www.forum4designers.co
    -----------------------------------------------------------------------
    View this thread: http://www.forum4designers.com/message76745.htm
    hardyrj, Apr 30, 2004
    #1
    1. Advertising

  2. hardyrj

    Gadrin77 Guest

    hardyrj <4designers.com> wrote in message news:<4designers.com>...
    > I am doing a simple task where I am trying to create a table of cars
    > with column 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


    note the COMMENTS in the XSL below:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Note the output method -->
    <xsl:eek:utput method="html"/>
    <!-- Note the output method -->

    <xsl:template match="/">
    <style>
    th {background-color: whitesmoke;border: .25mm solid navy}
    </style>
    <div align="center">
    <h1>Cars for Sale</h1>

    <!-- Also note the use of the TABLE element ;) -->

    <table border="1" style="border-collapse: collapse; border: .25mm
    solid navy" cellpadding="3">
    <tr>
    <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 align="center">
    <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="accessories/radio"/>
    </td>
    <td>
    <xsl:value-of select="accessories/air_conditioning"/>
    </td>
    <td>
    <xsl:value-of select="accessories/power_windows"/>
    </td>
    <td>
    <xsl:value-of select="accessories/power_steering"/>
    </td>
    <td>
    <xsl:value-of select="accessories/power_brakes"/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </div>
    </xsl:template>
    </xsl:stylesheet>
    Gadrin77, Apr 30, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WJ
    Replies:
    2
    Views:
    590
    Andy Dingley
    Dec 5, 2003
  2. Vijay singh
    Replies:
    1
    Views:
    435
    Martin Honnen
    Nov 4, 2004
  3. icedgar
    Replies:
    1
    Views:
    357
    Joris Gillis
    Feb 7, 2005
  4. Replies:
    1
    Views:
    3,600
    A. Bolmarcich
    May 27, 2005
  5. Rob Smegma
    Replies:
    1
    Views:
    1,808
    shaun
    Sep 26, 2005
Loading...

Share This Page