Log in

View Full Version : XML image



ftriantos
12-16-2005, 06:57 PM
Trying to get into xml. Lets say I have an XML document with an attached XSLT style sheet similar to this:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="search_results.xsl"?>
<results>
<profile id="01">
<name>
<first>Fred</first>
<last>Noone</last>
</name>
<img src="fred.jpg" />
</profile>
<profile id="02">
<name>
<first>Cindy</first>
<last>Someone</last>
</name>
<img src="cindy.jpg" />
</profile>
</results>

with XSLT looking like this:

<?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"/>
<xsl:template match="/">
<style>
div.profile{
border:1px solid red;
width:350px;
height:200px;
}
div.name{
border:1px dashed blue;
width:100%;
}
span.name{
font.weight:bold; font.style:arial;
}
</style>
<html>
<head>
<title>Search Results</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="profile">
<div class="profile">
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="name">
<div class="name">
<span class="name">
<xsl:value-of select="last" />,
<xsl:value-of select="first" />
</span>
</div>
</xsl:template>
I would like the image to get added here as simple html img
</xsl:stylesheet>

--my question is how to add the image into the style sheet to display...I have posted where I would like it to go inside the style sheet.

Thanks in advance

ftriantos
12-23-2005, 02:53 PM
The answer is easy. I guess it just looked complicated the way I posted it:

in the xml:
<img>
<src>fred.jpg</src>
</img>

in the xslt put the desired output item in brackets:
<xsl:for-each select="results/profile">

<xsl:for-each select="img">
<img class="profile" src="{src}" />
</xsl:for-each>

</xsl:for-each>