RE: displaying images

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