Copied to clipboard

Flag this post as spam?

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


  • Garry Bain 149 posts 124 karma points
    Sep 08, 2009 @ 11:14
    Garry Bain
    0

    Showing pictures using Media Picker and XSLT

    Hello everyone,

    I currently have an xslt file that shows a list of News Items - each news item has  a media picker section that allows the user to "Choose" a photo to go with each article. I am struggling to show this picture and wondered if someone could point where my XSLT is going wrong: I tried this first:

    <img alt="">
    <xsl:attribute name="src">           
    <xsl:value-of select="umbraco.library:GetMedia(1313,false)/data [@alias = 'umbracoFile']"/>
    </xsl:attribute>
    </img>

    Which worked showing the same picture "ID of 1313" looping through each of the news items, but when I try to change this to choose each individual ID I don't get any errors, only the "Error reading xslt file" message on my page. This is what I tried:

    <img alt="">
    <xsl:attribute name="src">           
    <xsl:value-of select="umbraco.library:GetMedia(data [@alias = 'pic'],false())/data[@alias='umbracoFile']"/>
    </xsl:attribute>
    </img>

    In my Document Types > Generic properties my Media Picker is called "pic" so I presume that's right - can anyone see where it's going wrong?

    Cheers, Garry.

  • dandrayne 1138 posts 2262 karma points
    Sep 08, 2009 @ 11:32
    dandrayne
    0

    I changed a few things

    <xsl:if test="string(current()/data [@alias = 'pic']) != ''">
    <img alt="">
    <xsl:attribute name="src">
    <xsl:value-of select="umbraco.library:GetMedia(current()/data [@alias = 'pic'], 'false')/data [@alias = 'umbracoFile']"/>
    </xsl:attribute>
    </img>
    </xsl:if>

    *  Added a check for image before trying to write it
    *  Slightly adjusted getmedia call

    Give this a shot!
    Dan

  • Garry Bain 149 posts 124 karma points
    Sep 08, 2009 @ 11:35
    Garry Bain
    0

    Ahhh excellent worked great - it's been driving me mad because I'm not too good with XSLT but I could see everyone elses examples where pretty much the same. Thanks for the quick reply, Garry.

  • dandrayne 1138 posts 2262 karma points
    Sep 08, 2009 @ 12:00
    dandrayne
    0

    No worries, you'll get the hang of xslt and, if not love it, hate it just a little less ;-)

    It's always good to put checks around anything that might blow up - getmedia is one of those things

Please Sign in or register to post replies

Write your reply to:

Draft