|
Subject: Re: displaying images From: "Brett McLaughlin" <bmclaugh@xxxxxxxx> Date: Fri, 10 Dec 1999 16:18:03 -0600 |
>I am new to XSL programming, and am trying to learn it as I build a new
application. We are planning to use XML/XSL to display database results >in
a browser.
>My problem:
>I need to display an image based on the filename from the XML file. I
understand that the result tree simply needs to show the html needed to
display >the file (that being <img src="picture.jpg">)
>However the "picture.jpg" is what is coming in the XML file, and I can't
configure the XSL to transform it correctly. Can anyone help?
If the name of the image is in your XML, this is easy. For example, if your
XML looks like:
<root>
<pictures>
<picture>
<src>picture.jpg</src>
</picture>
</pictures>
</root>
your XSL could do:
<xsl:template match="pictures">
<!-- Do some HTML -->
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="picture/src"/>
</xsl:attribute>
</xsl:element>
<!-- Do some more HTML -->
</xsl:template>
Of course, this can also be done (more concisely) as:
<xsl:template match="pictures">
<!-- Do some HTML -->
<img src="{picture/src}"/>
<!-- Do some more HTML -->
</xsl:template>
Finally, if your XML looks more like (with multiple pics):
<root>
<pictures>
<picture>
<src>picture.jpg</src>
</picture>
<picture>
<src>picture2.jpg</src>
</picture>
<picture>
<src>picture3.jpg</src>
</picture>
</pictures>
</root>
you can:
<xsl:template match="pictures">
<!-- Do some HTML -->
<xsl:apply-templates/>
<!-- Do some more HTML -->
</xsl:template>
<xsl:template match="picture">
<img src="{src}"/>
</xsl:template>
OR
<xsl:template match="pictures">
<!-- Do some HTML -->
<xsl:for-each select="picture">
<img src="{src}"/>
</xsl:for-each>
<!-- Do some more HTML -->
</xsl:template>
If you have some different format or permutation in mind, let us know, and
we can try to help out.
-Brett
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: displaying images, Betty L. Harvey | Thread | Re: displaying images, taifui |
| Re: displaying images, Betty L. Harvey | Date | Re: displaying images, taifui |
| Month |