XML/XSD/XSL Display Problem

Nick Shaw

Usenet Archive
Joined
Jul 7, 2005
Messages
5
Reaction score
0
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'
xmlns:xsi='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" xmlns:xsl="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 xmlns:xs="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
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Nick Shaw wrote:


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" xmlns:xsl="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 xmlns:xsl="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">
 

Nick Shaw

Usenet Archive
Joined
Jul 7, 2005
Messages
5
Reaction score
0
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
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Nick said:
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".
 

Nick Shaw

Usenet Archive
Joined
Jul 7, 2005
Messages
5
Reaction score
0
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?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Nick said:
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 xmlns:pf="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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top