小编Ibr*_*him的帖子

将图像从XML插入XSL文档

我想知道是否有任何方法可以使用元素或属性在XML文件中声明图像,然后在XSL文件中使用此图像将其输入到表中,而不必在XSL中创建表并输入图像逐个进入表格单元格.这是我当前的XML文档(不完整,因为我只是测试它).

<?xml version= "1.0"?>
<?xml-stylesheet type="text/xsl" href="stylesheet4.xsl"?>
    <countries>
        <country> 
            <countryname>United States</countryname>
            <countryflag>bg_locale.jpg</countryflag>
        </country>

        <country>
            <countryname>United Kingdom</countryname>
        </country>

        <country>
            <countryname>Deutschland</countryname>
        </country>
        </countries>
Run Code Online (Sandbox Code Playgroud)

这是我创建的XSL文件和我尝试使用的方法:

<?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="/countries">
<html>
<body bgcolor="black">

<div id="container" style="100%">

<div id="header" style="background-color:black; height:60px"></div>


<div id="content_container" align="center">
    <div id="content" align="left" style="background: url('bg_locale.jpg');height:845px;width:848px">
    Content goes here
    <img src="logo_timber.jpg" align="left"/><br/>
<br/>
<br/>
<br/>
<table border="1">

<tr>
<xsl:apply-templates/>
</tr>

</table>
</div>

</div>

</div>
</body>
</html>

</xsl:template>

<xsl:template match="country">
<tr><td><xsl:value-of select="countryflag"/></td></tr>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我已创建了一个表,并希望XSL从XML文件中获取图像,然后将其放置,以便每个countryflag图像逐个显示在表中.

html xml xslt templates image

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

html ×1

image ×1

templates ×1

xml ×1

xslt ×1