Re: How to display img using XSLT

[email protected] 12 Mar 2007 09:35:57 -0700
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization http://groups.google.com
Message-ID <[email protected]>
On Feb 20, 12:34 am, "Chuck" <[email protected]> wrote:
> Hi,
>
> I am new to XSLT and I have an XML file in the format given below. For
> each item, I would like to diplay the img as a thumbnail (with the src
> from XML) and the title next to the image in each line:
> ================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="test3.xsl"?>
> <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xsl:version="1.0">
>  <item>
>   <title>CNN Title </title>
>   <link>http://www.cnn.com</link>
>   <description><img src="cnnImage.jpg" />This is CNN home page</
> description>
>    </item>
>   <item>
>   <title>Yahoo title</title>
>    <link>http://www.yahoo.com</link>
>   <description><img src="yahooImage.jpg" />This is yahoo home page</
> description>
>   </item>
> </html>
> ==============
> My code is this, however the image is not being displayed:
> ----------------------------
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
> Transform">
> <xsl:output method="html" />
> <xsl:template match="/">
> <link rel="stylesheet" href="style.css" type="text/css" />
> <xsl:for-each select="html/item">
>  <div>
> <span>
> <img width="120" height="90">
> <xsl:attribute name="src"><xsl:value-of select="@src"/></
> xsl:attribute>
> </img>
> </span>
> <span>
> <a class="link" style="valign:top">
> <xsl:attribute name="href"><xsl:value-of select="link" /></
> xsl:attribute>
> <xsl:value-of select="title" />
> </a>
> </span>
> </div>
>  <br />
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> -------------------
> I would really appreciate any help regarding this.
> Thanks

Your statement
  <xsl:attribute name="src"><xsl:value-of select="@src"/></
xsl:attribute>
is incorrect. The context node is the <item> element, but the src
attribute is not on the <item> element; it's on <description><img>. So
you want
  <xsl:attribute name="src"><xsl:value-of select="description/img/
@src"/></xsl:attribute>

Lars