[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: displaying images

Subject: Re: displaying images
From: "Brett McLaughlin" <bmclaugh@xxxxxxxx>
Date: Fri, 10 Dec 1999 16:18:03 -0600
displaying images in xsl
>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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.