• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML / XSL problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I have just started learning XML. After reading initial chapters from the book, I tried writing a program. Below is the XML file I wrote:
--------------------------------Class.xml-----------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ClassStudents.xsl"?>
<Class>
<Student>
<Name>Student1</Name>
<FavSubject>English</FavSubject>
</Student>

<Student>
<Name>Student2</Name>
<FavSubject>Hindi</FavSubject>
</Student>
</Class>
--------------------------------------------------------------------------
After this I wrote 'ClassStudents.xsl' file as below:
===============================ClassStudents.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="/">
<HTML>
<TITLE> My First XML Program</TITLE>
<BODY BGCOLOR='LIGHTGREY'>
<H1> Favourite Subjects of Students </H1>
<TABLE BORDER='1' BORDERCOLOR='BLUE' BGCOLOR='LIGHTBLUE'>
<TR>
<TH ALIGN="CENTER">NAME</TH>
<TH ALIGN="CENTER">FAVOURITE SUBJECT</TH>
</TR>
<xsl:for-each select="Class/Student">
<TR>
<TD><xsl:value-of select="Name"/></TD>
<TD><xsl:value-of select="FavSubject"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
===========================================================================
I stored both the files in the directory - C:\XMLPractice\
Now I opend IE 6.0+. In the Address field of IE, I entered the location of the xml file - C:\XMLPractice\Class.xml and pressed enter.
The page was displayed. However the table in the page only displayed the Header row -i.e. 'Name' and 'Favourite Subject'. The <xsl:for-each> part of xsl did not get executed and hence the data rows didn't appear in the table.
Can somebody please clarify me where is the problem?
Thanks in advance
Neha
[ September 05, 2003: Message edited by: Neha Purohit ]
[ September 05, 2003: Message edited by: Neha Purohit ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works with my IE 5.5 after I've fixed the namespace to "http://www.w3.org/1999/XSL/Transform" and added the missing closing tags for <xsl:template> and <xsl:stylesheet>. I can take a look at it when I get home (I've got IE 6.0 installed there).
 
Neha Purohit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lasse,
Yes its working now, the problem was with the URL I specified for xmlns:xsl, as you pointed out, it should be "http://www.w3.org/1999/XSL/Transform"> the 'XSL'and 'T' of Transform should be in Caps, which I had written in Small letters earlier.

Thanks a lot
Neha
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear that (besides, I forgot to test it with IE 6.0...)
 
Neha Purohit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lasse,
Now I am trying to define a schema for my above xml file.I referred www.xml.com site to read about schemas.....the schema file I wrote is as below:
--------------------------------ClassStudents.xsd--------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Class">
<xs:complexType>
<xs:sequence>
<xs:element name="Student" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string">
<xs:element name="FavSubject" type="xs:string">
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------------------------------------------------------
However I am now stuck on how to associate this schema file with my xml file.
The site doesn't seem to have covered this part.
Can you please help me into this!!
Thanks
Neha
[ September 08, 2003: Message edited by: Neha Purohit ]
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example I extracted from a IBM DeveloperWorks' tutorial:
 
Neha Purohit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lasse,
I think I am troubling you a lot. In the Class.xml file, I copied the xmlns:xsi.... part to my <Class> element, replacing the .xsd file name with the name of the xsd file I am using. Then I added a <Title> Tag under <Student> tag and saved my Class.xml file. Below is how the file looks now:
---------------------------Class.xml --------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ClassStudents.xsl"?>
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ClassStudentsSchema.xsd">
<Student>
<Name>Student1</Name>
<FavSubject>English</FavSubject>
<Title>title1</Title>
</Student>

<Student>
<Name>Student2</Name>
<FavSubject>Hindi</FavSubject>
</Student>
</Class>
---------------------------------------------------------------------
The files 'Class.xml','ClassStudents.xsl' and 'ClassStudentsSchema.xsd' are stored in C:\XMLPractice\ directory of my local PC.
Now I open my C:\XMLPractice\Class.xml in IE expecting an error as <Title> element is not defied in the schema. However I am not getting any error and the page is displaying the table ignoring the <Title> element.
Does using Schema needs a Web-server or what? Note that I am not using any Web server.

#####
I feel I should have entered this schema problem as a new Topic, however since I was using the same example, I thought this way it would be easier to explain the problem.
Sorry for the trouble Lasse and thanks for your help....
Neha
[ September 09, 2003: Message edited by: Neha Purohit ]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neha,
Ya when I tried with IE6.0 I DID not get any error and got the output as I wrote the elements including the <title>. But when the same document is being validated by XML Spy it is giving me an error and stating me that <title> is an unexpected child which is very mu ch true. I think IE is not validating the XML file against the Schema.Neha try using some good XML editor like XML Spy.
Cheers,
Gaya3.
-------------------------------------------------------------------------
Life is a Process of Continuous Learning...
 
Neha Purohit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gaya3,
Actually I don't have XML SPY or any other XML parser for that matter. And because of some constraints, I cann't download any such thing from my machine.
Why this doesn't work with IE, I mean why IE doesn't throw any error. I belive IE6.0 must be using an XML parser implementing the most recent XML specifications.
Can somebody let us know why this doesn't work with IE?
Thanks
Neha
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why this doesn't work with IE, I mean why IE doesn't throw any error.


Yes I tried it it behaves as said above. I am using IE 5.5
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange
Netscape 7.1 gives me the following error
Error loading stylesheet: Parsing a XSLT stylesheet failed.
reply
    Bookmark Topic Watch Topic
  • New Topic