Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML/XSD/XSL Display Problem

Reply
Thread Tools

XML/XSD/XSL Display Problem

 
 
Nick Shaw
Guest
Posts: n/a
 
      07-08-2005
Hi,

I'm trying to put my resume on my website, and I want to do it using
XML and XSL. If I don't include the schema in the mix, the xml
displays without a problem. When I add the schema location to the xml,
however, it doesn't seem to be displaying the html tags. It just puts
all the information on the screen in one big block, almost like it's
reading the xml information, but not the html I have in my XSL. I know
all the XML/XSL/XSD stuff is well-formed because I have an editor
(XMLSpy) to yell at me for that kind of stuff. Here's what I have so
far:

---BEGIN XML---

---XML---
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="resume.xsl"?>
<resume xmlns='http://www.nickshaw.net'
xmlnssi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.nickshaw.net resume.xsd'>
<contact-info>
<name>Nicholas J. Shaw</name>
<address location="Home">
...

---XSL---
<xsl:stylesheet version="1.0" xmlns="http://www.nickshaw.net"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/resume">
<html>
<head>
<title>Resume</title>
<link rel="stylesheet" type="text/css" media="screen"
href="resume.css" />
</head>
<body>
<h1>
<xsl:value-of select="contact-info/name"/>
</h1>

<xsl:for-each select="contact-info/phone-number">
<xsl:value-of select="@location" />: <xsl:value-of
select="/resume/contact-info/phone-number" /><br/>
</xsl:for-each>

E-Mail: <xsl:value-of select="contact-info/e-mail" /><br/>

<xsl:for-each select="contact-info/address">
<p>
<h3><xsl:value-of select="@location" /></h3>
<xsl:value-of select="street-1"/>
<xsl:if test="street-2">, <xsl:value-of
select="street-2"/><br /></xsl:if>
<xsl:if test="not(street-2)"><br /></xsl:if>
<xsl:value-of select="city"/>, <xsl:value-of
select="state"/><br />
<xsl:value-of select="zip"/>
</p>
</xsl:for-each>

<h3>Objective</h3>
<p><xsl:value-of select="objective" /></p>

<h3>Skills</h3>
<xsl:for-each select="skill-set/skill-group">
<h4><xsl:value-of select="@name" /></h4>
<ul>
<xsl:for-each select="skill">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>

<h3>Education</h3>
<xsl:for-each select="education">
<xsl:value-of select="university" /><br />
<xsl:value-of select="start-date" /> through <xsl:value-of
select="end-date" /><br />
<xsl:if test="expected-graduation">
<xsl:value-of select="expected-graduation" /><br />
</xsl:if>
<ul>
<xsl:for-each select="degree">
<li><xsl:value-of select="@type" /> in <xsl:value-of
select="." /></li>
</xsl:for-each>
</ul>
<ul>
<xsl:for-each select="gpa">
<li><xsl:value-of select="@type" />: <xsl:value-of
select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>

<h3>Coursework</h3>
<xsl:for-each select="coursework/class-group" >
<xsl:value-of select="@name" /><br />
<ul>
<xsl:for-each select="class">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>

<h3>Work Experience</h3>
<xsl:for-each select="work-experience/job">
<xsl:value-of select="company" /> - <xsl:value-of
select="location" /><br />
<xsl:value-of select="job-title" /> - <xsl:value-of
select="start-date" /> through <xsl:value-of select="end-date" /><br />
<ul>
<xsl:for-each select="responsibility">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>

<h3>References</h3>
<ul>
<xsl:for-each select="references/reference">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

---XSD---
<?xml version="1.0"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.nickshaw.net"
targetNamespace="http://www.nickshaw.net"
elementFormDefault="qualified">
<xs:element name="resume">
<xs:complexType>
<xs:all>
<xs:element name="contact-info">
...

---END XML--

I think this is a problem with namespaces (or I could be completely
wrong). I am pretty new to all this (As of about 2 days ago). Any help
anyone could provide will be greatly appreciated. If you need any more
information, just ask. Thanks!

Nick Shaw

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      07-08-2005


Nick Shaw wrote:


> <resume xmlns='http://www.nickshaw.net'


You have a default namespace here meaning your <resume> element and its
child elements are in the namespace with the URI http://www.nickshaw.net.


> <xsl:stylesheet version="1.0" xmlns="http://www.nickshaw.net"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/resume">
> <html>


You again set the default namespace meaning now that <html> element is
in the namespace with the URI http://www.nickshaw.net while you probably
want to create HTML output where the <html> element should be in no
namespace. So you likely want
<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://www.nickshaw.net"
version="1.0">
<xsl:template match="ns:resume">
<html>
Of course as your input elements are in a namespace you need to make
sure all your XPath expressions and match patterns have the proper
prefix e.g. stuff like
<xsl:for-each select="contact-info/address">
needs to be
<xsl:for-each select="ns:contact-info/ns:address">

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Nick Shaw
Guest
Posts: n/a
 
      07-08-2005
Worked perfect! So just to make sure I understand this, the HTML was
being output to another namespace instead of to no namespace which was
making it unable to render the HTML in the browser? I thought I had it
all in no namespace (the XML and the XSL, anyway) and it was working
fine, but when I added in the schema, it caused problems because it was
in a namespace? Is it possible to have the schema and not have to
prefix every XPath expression with some namespace qualifier? Sorry if
these are very naive questions, but I'm having a little trouble with
this concept of namespaces. Thanks!

Nick Shaw

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-08-2005

Nick Shaw wrote:

> Is it possible to have the schema and not have to
> prefix every XPath expression with some namespace qualifier?


It is possible to write a schema for elements in no namespace, don't use
the targetNamespace then and use elementFormDefault="unqualified".

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Nick Shaw
Guest
Posts: n/a
 
      07-08-2005
Ok, that makes sense. One last question: As far as best practice, it
is probably best to specify a namespace rather than to use the default
namespace to qualify elements to prevent collisions, correct?

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-09-2005


Nick Shaw wrote:

> One last question: As far as best practice, it
> is probably best to specify a namespace rather than to use the default
> namespace to qualify elements to prevent collisions, correct?


To prevent collisions it is best practice to define your elements in a
namespace when you set up a schema.
Whether you make use of a default namespace or not is another and
unrelated question, a default namespace is only a tool to shorten your
XML once you have decided to use a namespace.
In the XML document

<root>
<text>Kibology for all.</text>
</root>

all elements are in no namespace and if someone uses that XML with XML
from different sources it will not be possible to distinguish for
instance the <root> element above from a <root> element elsewhere which
was meant to have a different semantics.
That is why people put their elements in a namespace but it is then
simply more convenient to write the XML as e.g.

<root xmlns="http://example.com/2005/07/ex1">
<text>Kibology for all.</text>
</root>

than to write

<pf:root xmlnsf="http://example.com/2005/07/ex1">
<pf:text>Kibology for all.</text>
</pf:root>

both ways the elements are now in the namespace with the URI
http://example.com/2005/07/ex1.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display byte array back to pdf and display in IE SG Java 6 01-15-2008 01:02 PM
choosing to display or not to display a checkbox in repeater control. Imran Aziz ASP .Net 4 08-11-2005 05:00 PM
Gateway laptop display display problem Michael Brown Computer Information 0 11-13-2004 11:03 PM
Double double display display problem problem Tom Accuosti Firefox 3 09-27-2004 10:02 PM
Display and display model Marc Twain Java 1 01-13-2004 07:05 PM



Advertisments