XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 29th, 2004, 06:37 PM
raisin raisin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 raisin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Outputting XHTML from XML using XSLT

Hello!

I'm having a few difficulties taking my xml document, applying a XSLT style to it and having it come out as XHTML in my browser. What I keep getting it just a formatted XML document when I view the source, but according to all the examples and references I've looked at it this is wrong.

Here are the key parts of the files I'm using:

XML
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="./styles/xsl/index.xsl"?>
<news>
    <post>
        <author>author</author>
        <subject>subject</subject>
        <body>text</body>
    </post>
</news>


XSL
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="no" omit-xml-declaration="no" />
<xsl:template match="/news">
<html>
<head>
      <title>title</title>
      </head>
<body>
<xsl:for-each select="post">
    <h2>Posted on Monday, August 23rd 2004 @ 5:06pm by <a href="#"><xsl:value-of select="author" /></a></h2>
		<h1><xsl:value-of select="subject" /></h1>
		<p><xsl:value-of select="body" /></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


and what I should see output by my browser:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<body>
...etc...
</body>
</html>


but what I actually see is something like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="./styles/xsl/index.xsl"?>
<news>
<post>
<author>author</author>
<subject>subject</subject>
<body>text</body>
</post>
</news>


Any help or tips with this would be greatly appreciated. I've been purging every resource available to try and find out my mistake, but to no avail.

As an added note, I'm using PHP to send "content-type:text/xml" to the header while I'm generating my XML file. Would this be overiding the XSL file in any way when it's trying to output XHTML?

Thanks,
raisin

Reply With Quote
  #2  
Old August 29th, 2004, 08:21 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
Quote:
Code:
<xsl:output method="xml" ...
Seems to be doing exactly what you've told it. I believe if you want HTML output, you need to use "html"; XHTML comes by using the public-doctype as you have.

http://www.w3schools.com/xsl/el_output.asp
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #3  
Old August 29th, 2004, 08:35 PM
raisin raisin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 raisin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I tried using html for the method again, but it's still outputting the file the exact same way as before. The only thing that seems to have changed is that the page I'm using it on isn't rendering correctly (but I'm not really worried about that).

Reply With Quote
  #4  
Old August 30th, 2004, 01:07 AM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
First, make sure the xsl stylesheet is really being applied.
Move the stylesheet to the same directory as the xml and change the href appropriately.

Also, you may wish to rename your <body> tag in the xml so it's not duplicating the name of an HTML tag. It did not cause a problem for me, but it's good to eliminate possible problems.

Your xsl applies correctly in FireFox and IE6 (after I added the missing </body></html> tags). What browser are you using to view it in, and are you letting the browser do the transformation (e.g. you are typing the xml file location into the address bar)?

IE browsers earlier than 6 may not render the document correctly, if at all, as it supports only the working draft of xslt, not the current recommendation. Current Gecko browsers (like FireFox, Mozilla, Netscape 7) render correctly, as does IE6. Opera has no XSLT support at all, although I understand the next release will have it. In that browser all you would see (from your xml) is: author subject text

If none of this helps, answer the questions and, if you can, provide the full xml/xsl or a link to them-sometimes the 'buggy' part is hard to spot.

Reply With Quote
  #5  
Old August 30th, 2004, 03:43 AM
raisin raisin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 raisin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your replies!

I figured out that the xml-stylesheet was where I was going wrong. My browser was trying to parse the xsl file, but it failed because xml-stylesheet is really made more specifically for CSS (to replace the <link> in html 4.01), or so it seems at w3.

I'm generating the xml and then parsing it through the stylesheet via php now, and it's working beautifully. A reference is here for anyone who might be interested.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Outputting XHTML from XML using XSLT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT