Welcome to WebmasterWorld Guest from 54.224.230.193

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Whats wrong with my XML/XSL?

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

New User

10+ Year Member

joined:Sept 7, 2004
posts:34
votes: 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 ;)

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 20, 2002
posts:889
votes: 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
2:54 pm on Mar 31, 2006 (gmt 0)

New User

10+ Year Member

joined:Sept 7, 2004
posts:34
votes: 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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 20, 2002
posts:889
votes: 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

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

New User

10+ Year Member

joined:Sept 7, 2004
posts:34
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 20, 2002
posts:889
votes: 0


Just wrap all your current xml in another element
<whatever>
...
</whatever>
4:23 pm on Mar 31, 2006 (gmt 0)

New User

10+ Year Member

joined:Sept 7, 2004
posts:34
votes: 0


But I thought I did that with this line:

<freport_loc>Washington</freport_loc>

But it works without it and not with it :(

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 20, 2002
posts:889
votes: 0


How about

<freport_root>

<freport_loc>Washington</freport_loc>

<freports>
...
</freports>

</freport_root>

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

New User

10+ Year Member

joined:Sept 7, 2004
posts:34
votes: 0


Sounds like a good solution, so XML always needs a "root" node to include eveything like HTML <HTML> or else it wont work?
11:47 am on Apr 2, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 27, 2003
posts:637
votes: 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.