PDS
PDS

Reputation: 46

How to display image in XSL

I am trying to display an image using XSL. But i am unable to find the mistake

How do i add images using xsl .. unable to view image even though its available in the location mentioned

Sample Code

XML:

<?xml version = "1.0"?> 
<?xml-stylesheet type = "text/xsl" href = "F:\\xsl\\students.xsl"?> 
<class> 
   <student rollno = "393"> 
      <firstname>Dinkar</firstname> 
      <lastname>Kad</lastname> 
      <nickname>Dinkar</nickname> 
      <marks>85</marks> 
   </student> 
   <student rollno = "493"> 
      <firstname>Vaneet</firstname> 
      <lastname>Gupta</lastname> 
      <nickname>Vinni</nickname> 
      <marks>95</marks> 
   </student> 
   <student rollno = "593"> 
      <firstname>Jasvir</firstname> 
      <lastname>Singh</lastname> 
      <nickname>Jazz</nickname> 
      <marks>90</marks> 
   </student> 
   <FileName>F:/xsl/pic.jpg</FileName>
</class>

XSL :

<?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>Students</h2> 
            <xsl:for-each select = "class/FileName"> 
                <table border = "1"> 
                    <tr bgcolor = "#9acd32"> 
                        <td>
                            <img>
                                <xsl:attribute name="src">
                                    <xsl:value-of select="FileName" />
                                </xsl:attribute>
                            </img>
                        </td>
                    </tr>
                </table> 
            </xsl:for-each> 
         </body> 
      </html> 
   </xsl:template>  
</xsl:stylesheet>

Upvotes: 0

Views: 1930

Answers (1)

T.N Maurya
T.N Maurya

Reputation: 11

Replace this line <xsl:value-of select="FileName" /> with <xsl:value-of select="." />

Upvotes: 1

Related Questions