Re: How to display img using XSLT

[email protected] 15 Apr 2007 18:37:55 -0700
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization http://groups.google.com
Message-ID <[email protected]>
On Mar 12, 11:35 am, [email protected] wrote:
> 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- Hide quoted text -
>
> - Show quoted text -

I'm trying the exact same thing and can't get my image to load i have
tried it both from the c:/ drive and from a url. can anyone help me
and find out what im doing wrong

here is my code

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="crafting.xsl"?>

<item>
 <woodworking>
  <apprentice>
   <title>Campfire Materials</title>
   <desc><img src="heavy_rowan_hammer.JPG"/></desc>
   <mats1>5 Rowan Wood</mats1>
   <mats2>1 Kindling Material</mats2>
   <mats3>1 Ball of Twine</mats3>
  </apprentice>
</woodworking>
</item>


<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h3>Apprentice</h3>
    <table border="1">
    <tr bgcolor="#daa520">
      <th align="left">Name</th>
      <th align="left">Description</th>
      <th align="left">Materials(1)</th>
      <th align="left">Materials(2)</th>
      <th align="left">Materials(3)</th>
      <th align="left">Materials(4)</th>
      <th align="left">Materials(5)</th>
    </tr>
    <xsl:for-each select="item/woodworking/apprentice">
      <xsl:value-of select="title"/>
      <xsl:attribute name="src"><xsl:value-of select="desc/img/@src"/
></xsl:attribute>
      <xsl:value-of select="mats1"/>
      <xsl:value-of select="mats2"/>
      <xsl:value-of select="mats3"/>
      <xsl:value-of select="mats4"/>
      <xsl:value-of select="mats5"/>
    </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>