如何使用XSLT以HTML格式显示图像? [英] How to display an image in HTML using XSLT?

查看:850
本文介绍了如何使用XSLT以HTML格式显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用XSLT输出我的XML所拥有的数据。设置的要求之一是在XML文件中包含图像文件:

I've been trying to use XSLT to output data that my XML has. One of the requirements that is set is to have an image file in the XML file:

<room id="001">
    <capacity>2 Adults</capacity>
    <room_name>King Double</room_name>
    <cost_st>$1700</cost_st>
    <cost_lt>$3400</cost_lt>
    <loc>Ground Floor</loc>
    <info>&in2;</info>
    <feat>&ft2;</feat>
    <deal>&pk2;</deal>
    <photo>kingdouble.jpg</photo>
</room>

虽然我可以在标签之间抓取字符串,但我似乎无法显示图像文件。我在这里写错了,还是在XSLT中出错?

While I can grab the string in between the tags, I can't seem to display the image file. Am I writing something wrong here, or is it an error in the XSLT?

编辑:
这是我的XSLT的一部分:

This is a portion of my XSLT:

    <tr border="2" bgcolor="#ffebcd">
        <td> <xsl:value-of select="room_name"/> </td>
        <td> <xsl:value-of select="capacity"/> </td>
        <td> <xsl:value-of select="info"/> </td>
        <td> <xsl:value-of select="loc"/> </td>
        <td> <xsl:value-of select="feat"/> </td>
        <td> <xsl:value-of select="cost_st"/> </td>
        <td> <xsl:value-of select="cost_lt"/> </td>
    </tr>

</xsl:template>

我要做的是显示图像文件而不指定特定图像,因为XSLT文件将用作两个单独XML页面的模板。

What I'm trying to do is display the image file without specifying the particular image because the XSLT file will be used as a template for two separate XML pages.

推荐答案

假设您的XSLT片段运行正常,您可以添加另一个 td 包括对图像的引用,如下所示:

Assuming that your XSLT fragment is operating correctly, you can add another td that includes a reference to the image like this:

<td><img src="{photo}"/></td>

此处, {photo} 是< a href =https://www.w3.org/TR/xslt#dt-attribute-value-template =nofollow> 属性值模板

不工作?

如果文件位于HTML页面以外的目录中,则需要构建相对路径,例如

If the file is in a directory other than that of the HTML page, you'll need to construct a relative path, e.g,

<td><img src="images/{photo}"/></td>

或绝对路径,例如

<td><img src="http://example.com/some/path/to/images/{photo}"/></td>






仍然无效?

要调试图像路径,首先手动编写HTML并确保您的心智模型如何编写绝对或相对 @src 路径正确。然后,检查由XSLT生成的HTML源,以检查路径是否与经过验证的手工制作的路径匹配。

To debug the image path, first write the HTML by hand and ensure that your mental model of how to write an absolute or relative @src path is correct. Then, examine the HTML source being generated by the XSLT to check that the path matches your proven, hand-crafted path.

这篇关于如何使用XSLT以HTML格式显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆