Forum Moderators: open

Message Too Old, No Replies

Xml "works" when viewing .xml but not in .html

         

Acternaweb

5:58 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



I am brand new to XML, so forgive the basic question.

I have an .xml file that has nested tables, when I view the file in IE, it looks like the way I want it to. However, when I try to view in html,the only way it will work is if I have only 1 nested table.

Any ideas on what I am doing wrong?

This is the xml part.
<?xml version="1.0"?>
<sport>
<league>
<team>
<name></name>
<number></number>
<year></year>
</team>
</league>
</sport>

choster

6:02 pm on Mar 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Acternaweb, I did not understand your question. Are you transforming the XML or are you applying CSS?

Acternaweb

6:40 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



Hey choster

Not sure what transforming means, but this is the html code that I have. Bascially I am trying to have the XML presented on this html page.

This is the html, hope it makes it clearly on what I am trying to do. Thanks for the help

<xml id="filename" src="filename.xml"></xml>

<table cellpadding=6 cellspacing=6 border="1" datasrc="#filename">
<thead>
<tr bgcolor=silver>
<th>league</th>
<th>team</th>
<th>name</th>
<th>number</th>
<th>year</th>
</tr>
</thead>

<tr>
<td><div dataFld="league"></div></td>
<td><div dataFld="team"></div></td>
<td><div dataFld="name"></div></td>
<td><div dataFld="number"></div></td>
<td><div dataFld="year"></div></td>
</table>

syber

6:45 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



When you bring up an XML file in IE, IE knows to apply a stylesheet to is so that you can see the XML structure. However, if you bring an HTML file into IE, IE is not going to apply the stylesheet, it is only going to show the HTML code.

johnl

11:31 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



hi acternaweb,

- if you perhaps could provide a simplified (but not too simplified) example for your xml-file, as eg. 'x.xml':


<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xml" href="x.xsl"?>
<sport>
<league>
<lnam>champions</lnam>
<team>
<tnam>superteam</tnam>
<pnam>miller</pnam>
<tnum>33</tnum>
<year>2005</year>
</team>
</league>
<league>
<lnam>losers</lnam>
<team>
<tnam>subteam</tnam>
<pnam>filler</pnam>
<tnum>32</tnum>
<year>2004</year>
</team>
</league>
</sport>

- and if you also could provide an example for the wanted output, eg:


league team name number year
champions superteam miller 33 2005
losers subteam filler 32 2004

- then maybe one of the forum members could explain to you that:

to generate the wanted output you will have to
provide an xsl-file, eg. 'x.xsl' which is called by the second line of 'x.xml' when you click on 'x.xml'.

this file would look similar to the following:


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>

<xsl:template match="/">
<html><head><title>x.xml transformed by x.xsl</title></head>
<body>
<table cellpadding="6" cellspacing="6" border="1">
<thead>
<tr bgcolor="silver">
<th>league</th>
<th>team</th>
<th>name</th>
<th>number</th>
<th>year</th>
</tr>
</thead>

<xsl:apply-templates/>
</table>
</body></html>
</xsl:template>

<xsl:template match="league">
<tr>
<td><xsl:value-of select=".//lnam"/></td>
<td><xsl:value-of select=".//tnam"/></td>
<td><xsl:value-of select=".//pnam"/></td>
<td><xsl:value-of select=".//tnum"/></td>
<td><xsl:value-of select=".//year"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>

then you would have a kind of starting point.
good luck!

Charlie Chan

11:45 pm on Apr 10, 2005 (gmt 0)

10+ Year Member



I have been working on a learning project I created. It might help you to look the files over. I can zip them to you if you would like them. It is a simple but interesting project that works.