Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Mar 28, 2011 @ 16:44
    dominik
    0

    GetMedia XSLT Problem

    Hello,

    I cant get the URL from my selected get media Item:

    This is my xslt:

    <xsl:for-each select="$currentPage/self::* //homeSlider/items/item">
      <xsl:variable name="media" select="./data [@alias = 'homeBGImage']" />
      
      <xsl:variable name="url">
        <xsl:text>/images/home/default.jpg</xsl:text>
      </xsl:variable>
      
       <xsl:if test="$media">
            <xsl:variable name="url" select="umbraco.library:GetMedia($media, 0)" />
      </xsl:if>

    This does not work. the variable media includes the ID (i tested this).

    How can i get the URL of the "media" id?

    I am using umbraco 4.5.2

  • Mike Chambers 636 posts 1253 karma points c-trib
    Mar 28, 2011 @ 16:49
    Mike Chambers
    0
    umbraco.library:GetMedia($media, 0)/umbracoFile

    <xsl:value-of select="umbraco.library:GetMedia($media, 0)" /> might be useful for you to see what it actaully returns..

  • dominik 711 posts 733 karma points
    Mar 28, 2011 @ 17:01
    dominik
    0

    If i use your script i also get an xslt parsing error. Perhaps the problem is that one of my items does not have any homeBGImage?

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 28, 2011 @ 17:05
    Jan Skovgaard
    0

    Hi Dominik

    If I remember correctly there is a bug with GetMedia in 4.5.2.

    What does the returned XML look like if you make a copy-of? Like

    <textarea>
    <xsl:copy-of select="$media" />
    </textarea>

    It should be fairly easy to fix this afterall but if I remember correctly you need to make a minor fix in the XSLT match.

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 28, 2011 @ 17:05
    Jan Skovgaard
    0

    What is the parsing error you receive by the way?

    /Jan

  • dominik 711 posts 733 karma points
    Mar 28, 2011 @ 17:47
    dominik
    0

    Hi Jan,

    I cannnot tell you the exact parsing error because  i use redirect and i always have to check the checkbox above the xslt to get xslt working with redirects.

    I read this is an error in Umbraco.

    I will try your solution and will come back

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 28, 2011 @ 19:44
    Kim Andersen
    0

    Hi Dominik

    If you're absolutely sure that the media-variable contains a media-node id you should be able to get the path to the file like this:

    <xsl:if test="$media != ''">
            <xsl:variable name="url" select="umbraco.library:GetMedia($media, 0)/umbracoFile" />
      </xsl:if>

    The parsing error that you get might be because you are creating a variable called url, but you already have declared a variable with that name ealier in your code. And you can't have two variables with the same name.

    /Kim A

  • dominik 711 posts 733 karma points
    Mar 29, 2011 @ 07:53
    dominik
    0

    Ok now i use a choose statement and it works.

    I didnt know that it is not possible to overwrite a variable (like I can do in some other languages).

    Now it works.

    Thanks

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 29, 2011 @ 11:42
    Kim Andersen
    0

    Great to hear Dominik!

    Yeah, it's good to know that you can't overwrite a variable like you can in eg. JavaScript etc. But you can have the same variable name if you're inside different scopes in your XSLT code. But for now it's just great that you got things working :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft