homepage Welcome to WebmasterWorld Guest from 54.166.148.189
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Whats wrong with my XML/XSL?
roxpace




msg:702384
 4:08 am on Mar 31, 2006 (gmt 0)

I have created two files, one XML and one XSL, but it outputs only HTML table header and no data which I instruct it to do, can anyone look at it and tell me what I do wrong?

By the way, I am using DOM XML in PHP5 for parsing, it works fine with PHP example files but not with my files.

TEST.XML
--------

<?xml version='1.0' encoding="ISO-8859-1"?>

<freport_loc>Washington</freport_loc>

<freports xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='host.xsd'>

<freport id='200603268765427382'>
<title type="text">What a day!</title>
<date type="date">2006-03-26</date>
<editorname type="text">James W</editorname>
<articlecontent type="text">
This is a test test, hope it works.
</articlecontent>
</freport>
<freport id='200603228765394857'>
<title type="text">Nothing works today</title>
<date type="date">2006-03-22</date>
<editorname type="text">Edvin</editorname>
<articlecontent type="text">
Maybe I shall write something, but not today
</articlecontent>
</freport>

TEST.XSL
--------

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="ISO-8859-1" />

<xsl:template match="/">
<h2>Style example</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Date</th>
<th>Descriptiontext</th>
</tr>
<xsl:for-each select="freport">
<xsl:sort select="date"/>
<tr>
<td><xsl:value-of select="date"/></td>
<td><xsl:value-of select="articlecontent"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

I need to get out all freport nodes sorted by date.

Hope someone knows the answer, thanks in advance ;)

 

Iguana




msg:702385
 9:55 am on Mar 31, 2006 (gmt 0)

That XML file doesn't look valid to me - can you call it up in Internet Explorer? I get 'only one top level element allowed' because of the <freport_loc> element

roxpace




msg:702386
 2:54 pm on Mar 31, 2006 (gmt 0)

I forgot to add the last line to the XML file in the posting, this one:

</freports>

It shows and works fine in IE, not of course with XSL... And I can parse it with expat method, but not successfully with DOM XML and XSLT, but as I said works fine with examples, even those on en.wikipedia.org

Iguana




msg:702387
 3:02 pm on Mar 31, 2006 (gmt 0)

I added in the closing </freports> myself before I tried to call it up in IE. As I said I got that error caused by the <freport_loc> - removed that tag and it was fine. I'm on IE6.

There can only be one root element - you have two. I ran it through o'reilly's on-line xml validator as well

roxpace




msg:702388
 3:37 pm on Mar 31, 2006 (gmt 0)

But what if I wanna add a node which marks the location but doesnt shall show up in freports, how do I do then because I should not place it within freports, that would be wrong structure wise.

And still it doesnt show up at all in PHP5 with DOM XML, works only with expat and no XSL.

Iguana




msg:702389
 4:08 pm on Mar 31, 2006 (gmt 0)

Just wrap all your current xml in another element
<whatever>
...
</whatever>

roxpace




msg:702390
 4:23 pm on Mar 31, 2006 (gmt 0)

But I thought I did that with this line:

<freport_loc>Washington</freport_loc>

But it works without it and not with it :(

Iguana




msg:702391
 5:19 pm on Mar 31, 2006 (gmt 0)

How about

<freport_root>

<freport_loc>Washington</freport_loc>

<freports>
...
</freports>

</freport_root>

roxpace




msg:702392
 1:09 am on Apr 1, 2006 (gmt 0)

Sounds like a good solution, so XML always needs a "root" node to include eveything like HTML <HTML> or else it wont work?

macrost




msg:702393
 11:47 am on Apr 2, 2006 (gmt 0)

That's correct. Think of it like a parent/child relationship.

<parent>
<child></child>
<child></child>
<child>
<another></another>
</child>
</parent>

In XML every tag must have a closing tag, and must be enclosed by a parent tag. Remember, you are creating a hierarchal structure to data.

Lemme take a closer look at your XSL.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved