aspose file tools*
The moose likes XML and Related Technologies and the fly likes Displaying an image from xml source element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Displaying an image from xml source element" Watch "Displaying an image from xml source element" New topic
Author

Displaying an image from xml source element

Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
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.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The syntax for an image tag in HTML is
<img src="...">
so your XSL stylesheet should probably look something like:


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
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
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Nov 07, 2003
Posts: 47
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying an image from xml source element