如何通过XSL从现有XML文件中的字符串正确调用图像? [英] How to call an image correctly through XSL from a string within an existing XML file?

查看:123
本文介绍了如何通过XSL从现有XML文件中的字符串正确调用图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将变换的xsl文件调用图像时出现问题。

I have an issue with calling an image across to my transformed xsl file.

这似乎很简单,但我找不到解决方法它。我已经尝试在这里搜索并使用提供的各种类似答案,但没有运气。

It seems to be something very simple, yet I can't find a solution to it. I have tried searching on here already and using the various similar answers provided but have had no luck.

我正在尝试使用里面的字符串

I'm trying to use the string inside

<image>string</image>

作为显示我的图形的文件路径。

as the filepath to display my graphic.

我试过的任何结果都会给我一个小破的图形图标。

Any resultant I've tried always gives me the small broken graphic icon.

提前致谢。

编辑:我会更具体。 (很抱歉它是一个漫长的一天)

I'll be more specific. (Sorry it's been a long day)

我用记事本+ +,与XML工具插件,我可以通过指定的XSL文件应用XSL转换时,我我专注于XML文件。
我把它保存为新创建的html文件。

I'm using Notepad++, with the "XML Tools" plugin, I can apply the XSL Transformation by specifying the xsl file when I am focused on the XML file. Where I save it as a newly created html file.

打开它应该显示我的所有数据+图像。但相反,我得到占位符,而不是找不到图形。 (即在Internet Explorer中它是带有红色十字的小图标。)

Opening it should display all my data + the image. But instead, I get the placeholder instead for when a graphic cannot be located. (i.e. in Internet Explorer its the small icon with the red cross.)

使用文件开头的样式表方法调用也应该允许我查看转换而不用需要使用Firefox创建任何新文件。但它也无法显示。

Using the stylesheet method call at the start of the file should also allow me to view the transformation without the need to create any new file using Firefox. But it also fails to display.

这是我的XML:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="aperture_event_page.xsl" type="text/xsl"?>
    <listings
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="aperture_venues.xsd">

        <venue id="apv_01">
            <image>/images/apv_01.png</image>
            <other elements></other elements>
            ...
            <more elements>
                <elements></elements>
                ...
            </more elements>
        </venue>

        <venue id="apv_02">
            #repeat#
        </venue>

        <venue id="apv_03">
            #repeat#
        </venue>

        <venue id="apv_04">
            #repeat#
        </venue>
    </listings/>

和我的XSL:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:element name="html">
            <xsl:element name="head">
                <xsl:element name="title">Event</xsl:element>
            </xsl:element>

            <xsl:element name="body">
                <xsl:element name="image">
                    <img src="{image}"/>
                </xsl:element>
                <xsl:apply-templates select="/listings/venue/image"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>


推荐答案

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" omit-xml-declaration="yes"/>
    <xsl:template match="/">
    <xsl:element name="html">
    <xsl:element name="head">
    <xsl:element name="title">Event: Concert</xsl:element>
    </xsl:element>
    <xsl:element name="body">
    <xsl:apply-templates select="/listings/venue/event[@id='eve_01']"/>
    </xsl:element>
    </xsl:element>
    </xsl:template>
    <xsl:template match="event">
    <xsl:element name="img">
    <xsl:attribute name="src">
    <xsl:text>
    http://url to image path/xml/task2/event_page
    </xsl:text>
    <xsl:value-of select="../image/text()"/>
    </xsl:attribute>
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

使用xsl:text,我能够指定图像路径网址然后接收图像元素string作为完成完整路径的文件名。

Using xsl:text, I was able to specify the image path url and then take in the image element string as the filename to complete the full path.

这篇关于如何通过XSL从现有XML文件中的字符串正确调用图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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