Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael McAiney 14 posts 33 karma points
    Apr 04, 2012 @ 01:37
    Michael McAiney
    0

    Show image from Media in XSLT

    Hi All

    I have been trying all night to succesfully show an image from my Media store in a XSLT file I am building.  I was to pass in the Media ID and then return the image URL.

    If I do this:  <xsl:value-of select="umbraco.library:GetMedia(1119, 'false')"/>  

    It returns this : ~/media/64/serviceimage1.jpg125818285jpg

    Which is not quite right.

    After looking around for the answer on how to return the real URL I changed it to this:

    <xsl:value-of select="umbraco.library:GetMedia(1119,'false')/data [@alias='umbracoFile']"/> 

    It keeps returning nothing!

    I have tried changing it to return width and height but it still returns nothing. 

    Any ideas ?

  • David Conlisk 432 posts 1008 karma points
    Apr 04, 2012 @ 11:56
    David Conlisk
    0

    Hi Michael,

    What version of Umbraco are you using? It looks like you're using the old xslt syntax. Try this, which should work with the new xml format that Umbraco uses:

    <xsl:value-of select="umbraco.library:GetMedia(1119,'false')/umbracoFile"/>

    Cheers,

    David



  • Michael McAiney 14 posts 33 karma points
    Apr 04, 2012 @ 20:40
    Michael McAiney
    0

    Hi David

    Thank you for that.

    I am using version 4.7.1.1

    Your fix above is now returning something which looks more like a proper URL.  I am now getting: ~/media/64/serviceimage1.jpg

    I just did the following:

    <xsl:variable name="url" select="umbraco.library:GetMedia(1119,'false')/umbracoFile"/>

    <img src="{$url}" />

    And it throws an error! 

    The relative virtual path '="' is not allowed here

    Any ideas?

  • Michael McAiney 14 posts 33 karma points
    Apr 04, 2012 @ 20:49
    Michael McAiney
    0

    I have done the following to remove the ~

    <xsl:variable name="url" select="translate(umbraco.library:GetMedia(serviceThumbnailImage,'false')/umbracoFile, '~', '')"/>

    Surely I am working around the issue here though ?  Whats the correct way of doing it ?

     

    Thanks!

  • David Conlisk 432 posts 1008 karma points
    Apr 04, 2012 @ 21:05
    David Conlisk
    0

    Probably not much help, but it looks to me like you are doing it correctly. I haven't seen that tilde issue before. I'm using the following:

    <xsl:variable name="image" select="umbraco.library:GetMedia(image, 'false')"/>
    <xsl:value-of select="$image/umbracoFile"/>

    I've also tried it like this:

    <xsl:variable name="url" select="umbraco.library:GetMedia($currentItem/image, 'false')/umbracoFile"/>
    <xsl:value-of select="$url"/>

    And the output for both is

    /media/3212/slide-1.jpg

    Which is as expected, i.e. without the tilde.

    I'm not sure what could be causing this. Are you running your site in IIS at the moment? Or just hitting F5 in Visual Studio? I'm clutching at straws ;)

    David

    • media/3206/slide-1.jpg
    • media/3206/slide-1.jpg
  • Michael McAiney 14 posts 33 karma points
    Apr 04, 2012 @ 21:08
    Michael McAiney
    0

    Its running under IIS...

    Thanks for your help.  I seem to have a habit at attracting issues no one else has at the moment :D

    Anyway this workaround should get me moving on but if anyone else has any idea then please le me know.

     

    Thanks for your help David

Please Sign in or register to post replies

Write your reply to:

Draft