Can't get my XSL Stylesheet working..

Discussion in 'XML' started by Jonathan, Nov 8, 2003.

  1. Jonathan

    Jonathan Guest

    At the moment I have 3 files: a small XML instance document, a schema
    (which the .xml validates against fine) and a work-in-progress .xsl.
    (posted below)
    The problem is that I cannot get the stylesheet to grab any data from
    the XML document so I just end up with an empty HTML file.
    However, if I change the XML file to look at an equivalent DTD
    (instead of the XSD) it works as it should.
    Any help would be greatly appreciated. I have posted a sample of my
    code below.

    Thanks in advance.


    films.xsd:

    <?xml version="1.0"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.mycompany.com/filmcatalog"
    xmlns:target="http://www.mycompany.com/filmcatalog"
    elementFormDefault="qualified">

    <element name="filmcatalog">
    <complexType>
    <sequence>

    <element name="Film" maxOccurs="unbounded">
    <complexType>
    <group ref="target:FilmGroup" />
    </complexType>
    </element>

    </sequence>
    </complexType>
    </element>

    <group name="FilmGroup">
    <sequence>
    <element name="film_title" type="normalizedString" maxOccurs="2" />
    <element name="film_year" type="gYear" />
    <element name="runtime" type="nonNegativeInteger" />
    <element name="director" type="target:DirectorType" />
    <element name="writers" type="target:WriterType" />
    <element name="cast" type="target:CastType" maxOccurs="unbounded" />
    <element name="film_summary" type="string" minOccurs="0" />
    <element name="memorable_Quote" type="normalizedString" minOccurs="0"
    maxOccurs="unbounded" />
    <element name="film_certUK" type="string" minOccurs="0" />
    </sequence>
    </group>

    <complexType name="DirectorType">
    <sequence>
    <element name="name" type="string" maxOccurs="2" />
    </sequence>
    </complexType>

    <complexType name="WriterType">
    <sequence>
    <element name="name" type="string" maxOccurs="unbounded" />
    </sequence>
    </complexType>

    <complexType name="CastType">
    <sequence>
    <element name="name" type="string" />
    <element name="role_played" type="token" minOccurs="1"
    maxOccurs="unbounded" />
    </sequence>
    </complexType>
    </schema>


    Films.xml:

    <?xml version="1.0"?>
    <!--<!DOCTYPE filmcatalog SYSTEM "films.dtd">
    <filmcatalog>!-->
    <filmcatalog
    xmlns="http://www.mycompany.com/filmcatalog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mycompany.com/filmcatalog films.xsd">

    <Film>

    <film_title>The Big Lebowski</film_title>
    <film_year>1998</film_year>
    <runtime>117</runtime>
    <director>
    <name>Joel Coen</name>
    </director>
    <writers>
    <name>Ethan Coen</name>
    <name>Joel Coen</name>
    </writers>
    <cast>
    <name>Jeff Bridges</name>
    <role_played>Jeff 'The Dude' Lebowski</role_played>
    </cast>
    <cast>
    <name>John Goodman</name>
    <role_played>Walter Sobchak</role_played>
    </cast>
    <cast>
    <name>Steve Buscemi</name>
    <role_played>"Donny"</role_played>
    </cast>
    <film_summary>Dude Lebowski, mistaken for a millionaire Lebowski,
    seeks restitution for his ruined rug and enlists his bowling buddies
    to help get it.</film_summary>
    <memorable_Quote></memorable_Quote>
    <film_certUK>18</film_certUK>

    </Film>
    </filmcatalog>


    and Films.xsl:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" encoding="UTF-8"/>

    <xsl:template match="/">
    <html>
    <head>
    <title><xsl:value-of select="filmcatalog/Film/film_title"/></title>
    </head>

    <body>
    <h1>Film: <xsl:value-of select="filmcatalog/Film/film_title"/></h1>
    <p>Year: <xsl:value-of select="filmcatalog/Film/film_year"/></p>
    <p>Summary: <xsl:value-of
    select="filmcatalog/Film/film_summary"/></p>
    <p>Runtime: <xsl:value-of select="filmcatalog/Film/runtime"/>
    mins.</p>
    <p>UK Certification: <xsl:value-of
    select="filmcatalog/Film/film_certUK"/></p>
    <p>Directors: <xsl:value-of
    select="filmcatalog/Film/director/name"/></p>
    <p>Writers: <xsl:value-of
    select="filmcatalog/Film/writers/name"/></p>
    <p><b>Cast</b><br/>
    <TABLE>
    <TR>
    <TH>Name</TH>
    <TH>Role</TH>
    </TR>
    <xsl:apply-templates select="filmcatalog/Film/cast"/>
    </TABLE></p>
    <p>Quote: "<xsl:value-of
    select="filmcatalog/Film/memorable_Quote"/>"</p>
    </body>
    </html>

    </xsl:template>


    <xsl:template match="filmcatalog/Film/cast">
    <TR>
    <TD><xsl:value-of select="name"/></TD>
    <TD><xsl:value-of select="role_played"/></TD>
    </TR>
    </xsl:template>

    </xsl:stylesheet>
     
    Jonathan, Nov 8, 2003
    #1
    1. Advertising

  2. This is a VFAQ.

    See: http://www.topxml.com/people/bosley/defaultns.asp


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL



    "Jonathan" <> wrote in message
    news:...
    > At the moment I have 3 files: a small XML instance document, a schema
    > (which the .xml validates against fine) and a work-in-progress .xsl.
    > (posted below)
    > The problem is that I cannot get the stylesheet to grab any data from
    > the XML document so I just end up with an empty HTML file.
    > However, if I change the XML file to look at an equivalent DTD
    > (instead of the XSD) it works as it should.
    > Any help would be greatly appreciated. I have posted a sample of my
    > code below.
    >
    > Thanks in advance.
    >
    >
    > films.xsd:
    >
    > <?xml version="1.0"?>
    > <schema xmlns="http://www.w3.org/2001/XMLSchema"
    > targetNamespace="http://www.mycompany.com/filmcatalog"
    > xmlns:target="http://www.mycompany.com/filmcatalog"
    > elementFormDefault="qualified">
    >
    > <element name="filmcatalog">
    > <complexType>
    > <sequence>
    >
    > <element name="Film" maxOccurs="unbounded">
    > <complexType>
    > <group ref="target:FilmGroup" />
    > </complexType>
    > </element>
    >
    > </sequence>
    > </complexType>
    > </element>
    >
    > <group name="FilmGroup">
    > <sequence>
    > <element name="film_title" type="normalizedString" maxOccurs="2" />
    > <element name="film_year" type="gYear" />
    > <element name="runtime" type="nonNegativeInteger" />
    > <element name="director" type="target:DirectorType" />
    > <element name="writers" type="target:WriterType" />
    > <element name="cast" type="target:CastType" maxOccurs="unbounded" />
    > <element name="film_summary" type="string" minOccurs="0" />
    > <element name="memorable_Quote" type="normalizedString" minOccurs="0"
    > maxOccurs="unbounded" />
    > <element name="film_certUK" type="string" minOccurs="0" />
    > </sequence>
    > </group>
    >
    > <complexType name="DirectorType">
    > <sequence>
    > <element name="name" type="string" maxOccurs="2" />
    > </sequence>
    > </complexType>
    >
    > <complexType name="WriterType">
    > <sequence>
    > <element name="name" type="string" maxOccurs="unbounded" />
    > </sequence>
    > </complexType>
    >
    > <complexType name="CastType">
    > <sequence>
    > <element name="name" type="string" />
    > <element name="role_played" type="token" minOccurs="1"
    > maxOccurs="unbounded" />
    > </sequence>
    > </complexType>
    > </schema>
    >
    >
    > Films.xml:
    >
    > <?xml version="1.0"?>
    > <!--<!DOCTYPE filmcatalog SYSTEM "films.dtd">
    > <filmcatalog>!-->
    > <filmcatalog
    > xmlns="http://www.mycompany.com/filmcatalog"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocation="http://www.mycompany.com/filmcatalog films.xsd">
    >
    > <Film>
    >
    > <film_title>The Big Lebowski</film_title>
    > <film_year>1998</film_year>
    > <runtime>117</runtime>
    > <director>
    > <name>Joel Coen</name>
    > </director>
    > <writers>
    > <name>Ethan Coen</name>
    > <name>Joel Coen</name>
    > </writers>
    > <cast>
    > <name>Jeff Bridges</name>
    > <role_played>Jeff 'The Dude' Lebowski</role_played>
    > </cast>
    > <cast>
    > <name>John Goodman</name>
    > <role_played>Walter Sobchak</role_played>
    > </cast>
    > <cast>
    > <name>Steve Buscemi</name>
    > <role_played>"Donny"</role_played>
    > </cast>
    > <film_summary>Dude Lebowski, mistaken for a millionaire Lebowski,
    > seeks restitution for his ruined rug and enlists his bowling buddies
    > to help get it.</film_summary>
    > <memorable_Quote></memorable_Quote>
    > <film_certUK>18</film_certUK>
    >
    > </Film>
    > </filmcatalog>
    >
    >
    > and Films.xsl:
    >
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="html" encoding="UTF-8"/>
    >
    > <xsl:template match="/">
    > <html>
    > <head>
    > <title><xsl:value-of select="filmcatalog/Film/film_title"/></title>
    > </head>
    >
    > <body>
    > <h1>Film: <xsl:value-of select="filmcatalog/Film/film_title"/></h1>
    > <p>Year: <xsl:value-of select="filmcatalog/Film/film_year"/></p>
    > <p>Summary: <xsl:value-of
    > select="filmcatalog/Film/film_summary"/></p>
    > <p>Runtime: <xsl:value-of select="filmcatalog/Film/runtime"/>
    > mins.</p>
    > <p>UK Certification: <xsl:value-of
    > select="filmcatalog/Film/film_certUK"/></p>
    > <p>Directors: <xsl:value-of
    > select="filmcatalog/Film/director/name"/></p>
    > <p>Writers: <xsl:value-of
    > select="filmcatalog/Film/writers/name"/></p>
    > <p><b>Cast</b><br/>
    > <TABLE>
    > <TR>
    > <TH>Name</TH>
    > <TH>Role</TH>
    > </TR>
    > <xsl:apply-templates select="filmcatalog/Film/cast"/>
    > </TABLE></p>
    > <p>Quote: "<xsl:value-of
    > select="filmcatalog/Film/memorable_Quote"/>"</p>
    > </body>
    > </html>
    >
    > </xsl:template>
    >
    >
    > <xsl:template match="filmcatalog/Film/cast">
    > <TR>
    > <TD><xsl:value-of select="name"/></TD>
    > <TD><xsl:value-of select="role_played"/></TD>
    > </TR>
    > </xsl:template>
    >
    > </xsl:stylesheet>
     
    Dimitre Novatchev, Nov 8, 2003
    #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. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    591
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. Steven An
    Replies:
    1
    Views:
    512
    Martin Honnen
    Nov 23, 2004
  3. Thomas Sommer
    Replies:
    0
    Views:
    434
    Thomas Sommer
    Nov 25, 2004
  4. MC
    Replies:
    1
    Views:
    7,295
    David Carlisle
    Mar 24, 2005
  5. Replies:
    0
    Views:
    545
Loading...

Share This Page