Click to See Complete Forum and Search --> : Images source from XML to XHTML


onggiadzit
11-05-2006, 01:48 PM
I created an XML file that has picture file name in it, how can I display the image in the html.
HELP!!!

here are my files:
------------ xml -------
<?xml version="1.0" encoding="utf-8"?>
<player>
<name>maria Doe</name>
<picture>maria.jpg</picture>
<residence>Tustin, CA</residence>
</player>

------------html -------
<html>
<body>
<xml id="cdcat" src="maria.xml"></xml>

<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="name"></span></td> <!--- this works--->
<td><span datafld="residence"></span></td> <!--- this works--->
<td><img border="0" src="'picture'" width="160" height="120"></span></td> <!--- this DOES NOT works. Don't know the sytax -->
</tr>
</table>

</body>
</html>

NogDog
11-05-2006, 02:34 PM
Are you using some proprietary tool or scripting language for this? (I ask because there is no "xml" element nor "datafld" attribute in the HTML specification.)

onggiadzit
11-05-2006, 02:42 PM
Those are the only files I have, and no other tools. FYI, I do not know anything about xml, i just read the xml tutor last night.

NogDog
11-05-2006, 03:11 PM
The normal, standards-compliant method would probably be to use a XSL stylesheet in conjunction with your XML file in order to define how things are displayed.

test.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<players>
<player>
<name>Maria Doe</name>
<picture>maria.jpg</picture>
<residence>Tustin, CA</residence>
</player>
<player>
<name>John Doe</name>
<picture>john.jpg</picture>
<residence>Tustin, CA</residence>
</player>
</players>

test.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />
<title>Page Title</title>
</head>
<body>
<xsl:for-each select="players/player">
<div class="artcle">
<h2><xsl:value-of select="name"/></h2>
<p><xsl:value-of select="residence"/></p>
<xsl:variable name="url" select="picture"/>
<p><img src="{$url}" alt=""/></p>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

onggiadzit
11-05-2006, 05:58 PM
Thank you NogDog.
I don't know how to use the xsl yet, something for me to learn tonight.
Thanksss!

Hey! it works. :cool: :cool: :cool: