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

RE: displaying images

Subject: RE: displaying images
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Fri, 10 Dec 1999 16:56:22 -0700
displaying image xslt
Matt Lowe wrote:
> 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">)

No, the result tree is a node tree (an abstract thing that exists only as
some kind of a data structure in the XSL processor). XSLT conveniently lets
you say how you want that node tree to be created via a syntax that looks
like XHTML. This syntax is described in the XSLT spec as "literal result
elements". So  for example in your stylesheet you can have

<img src="{foo}"/>

This tells the XSL processor to add an element named 'img' to the result
tree, with an attribute named 'src' and a value of the result of evaluating
the XPath expression foo. The XPath expression should be in curly braces and
should return a string or a node that you want to see the string value of.
String values for each node type are explained in the XPath spec.

If your source XML is like this:

<mydata>
  <ImageInfo>
    <Image ID="123" URI="picture.jpg"/>
  </ImageInfo>
</mydata>

And your context node was the 'ImageInfo' element, as in the case when you
match on it, the XPath expression to get the 'URI' attribute of the 'Image'
element that is a child of the context node is quite simply Image/@URI,
which you'd put in the curly braces:

<xsl:template match="ImageInfo">
  <img src="{Image/@URI}"/>
</xsl:template>

If you have the XSL processor serialize and emit the result tree as XML,
you'll see in the output

<img src="picture.jpg"/>

And if you have it serialize it as HTML, you'll see

<img src="picture.jpg">


Happy coding.


 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.