Reputation: 21
I have been trying to display image for quite sometimes now and some of the solutions in this website does not work for me...
This is my xslt code
<xsl:template match="/">
<div class="main">
<h2>Product Catalogue</h2>
<xsl:for-each select="productdetails/product">
<div class="box">
<img src="<xsl:value-of select="product_image"/>"> </img>
<xsl:value-of select="format-number(product_Price,'0.00')" />
<h3>
<xsl:value-of select="product_Name"/>
</h3>
RM<xsl:value-of select="format-number(product_Price,'0.00')" />
<br/>
<p style="font-size:9pt; font-style: italic;">
<xsl:value-of select="product_description"/>
</p>
<br/>
<a href="#" runat="server" onserverclick="Cart">Add to Cart </a>
</div>
</xsl:for-each>
</div>
</xsl:template>
Just so you know product_image in the xml is already the imagepath thats why I did not need to write the path in the xslt code.
Upvotes: 0
Views: 1358
Reputation: 116992
In XML, a tag cannot contain another tag - so this is invalid code:
<img src="<xsl:value-of select="product_image"/>"> </img>
Use either:
<img>
<xsl:attribute name="src">
<xsl:value-of select="product_image"/>
</xsl:attribute>
</img>
or:
<img src="{product_image}"/>
To understand the 2nd syntax, read about Attribute Value Templates.
Upvotes: 1