如何在XSL中显示图像

时间:2018-11-17 10:38:08

标签: xml xslt

我正在尝试使用XSL显示图像。但是我找不到错误

如何使用xsl添加图片。即使在上述位置也无法查看图片

示例代码

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>

1 个答案:

答案 0 :(得分:1)

将此行<xsl:value-of select="FileName" />替换为<xsl:value-of select="." />