• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Displaying an image from xml source element

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I seem to be having a problem displaying a image using a XSL transformation, and a source XML doc.
The source xml for the image I have is:

Within the xsl stylesheet which I am using to transform info. in my xml file to a suitable display I have the following code to retrieve the location of the image:

The image doesn't display in the browser.
I have embedded the xsl transformation in an <img> tag is it correct to do this? Could someone tell me the correct procedure to display this image using an xsl stylesheet transformation.
Thanks.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The syntax for an image tag in HTML is
<img src="...">
so your XSL stylesheet should probably look something like:
 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That didn't work for me, error message:
Cannot use <xsl:template> here.
I think its because I have a for-each statement before I insert your code snippet.
My xml tree structure is like this:
<Holiday>
<City>
<Media......>code like before in orginal post.
</City>
</Holiday>
I have a xsl:template match="/" at the start of my xsl:stylesheet.
Can you help me further?
Thanks.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cannot use <xsl:template> here.

Yes, the xsl:template element can only be used as a direct child of xsl:stylesheet.

I have a xsl:template match="/" at the start of my xsl:stylesheet.

It is a best practice to avoid writing your stylesheet as a one big, gigantic template element. If it's too much trouble at this point to divide your template into several smaller ones, you should try using my code snippet within the xsl:for-each (just the content of my xsl:template, not the whole thing).
It would probably also help a lot if you'd post your XSL document (using the UBB code tags for decent formatting, please).
 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,
I embedded your code snippet into my xsl:for-each statement as follows:

The result displays the alt element ok in the browser, bit still the image is not displayed, I just see the standard X where the image should be.
Also where would I put parameters for height and width into your code snippet for the image, just as an extra attributes I guess?
Here is a snippet of my xml source file which is relevant to this particular problem:

Let me know if you can help please, looks like something so simple to me, but so annoying.
Thanks for your help, Annemarie.
reply
    Bookmark Topic Watch Topic
  • New Topic