Reputation: 1
My XML is like below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter id="ch01">
<sect1>
<title>Wattage</title>
<para>Paragraph1</para>
<para>Paragraph2</para>
<para><figure>
<caption>
<para>
<i>Sample image caption</i></para>
</caption>
<img src="myimagepath\cover_front.jpg"/>
</figure>
</para>
</sect1>
</chapter>
I am having issues in displaying image on the HTML page where I am rendering my XML using XSLT (through C# aspx page).
My XSLT is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My Book</h2>
<xsl:apply-templates select="chapter/sect1" />
</body>
</html>
</xsl:template>
<xsl:template match="chapter/sect1">
<xsl:apply-templates select="title" />
<xsl:apply-templates select="para/figure" />
<br />
</xsl:template>
<xsl:template match="title">
<b><span style="font-size=22px;">
<xsl:value-of select="." />
</span>
</b>
<br />
</xsl:template>
<xsl:template match="para/figure">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
My Image is not displaying using above XSLT. Can anyone please help. I am new to XSLT.
Upvotes: 0
Views: 2465
Reputation: 10190
The point where you're rendering para/figure isn't doing quite what you think, the point at which you select "." for the image source should in fact render all of:
<caption><para><i>Sample image caption</i></para></caption>
<img src="myimagepath\cover_front.jpg"/>
Try changing this template: to:
<xsl:template match="para/figure">
<img src="{img/@src}" />
</xsl:template>
(that's working from memory) so:
Upvotes: 1