Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 14:16
    Dan
    0

    Loop through thumbnails of node, then thumbnails of subnodes

    Hi,

    As with most of my XSLT exploits, I've almost got this working, but just require that final nudge!

    I'm looping through a content node called media, picking out a thumbnail image for each media album.  I need to be able to then show thumbnails for each subnode, so I end up with an output like this:

    <ul>
    <li>
    <img src="Gallery-album-1.jpg" />
    <ul>
    <li><img src="Gallery-image-1.jpg" /></li>
    <li><img src="Gallery-image-2.jpg" /></li>
    </ul>
    </li>
    </ul>

    The code I have currently loops through the parent nodes, gets the image for each and loops through the child nodes.  What I'm struggling with is getting the images from the child nodes:

    <xsl:for-each select="umbraco.library:GetXmlNodeById(number($source))/descendant::node">
    <ul>
    <xsl:variable name="galImage" select="umbraco.library:GetMedia(current()/data[@alias='AlbumImage'], 'false')/data[@alias='umbracoFile']"/>
    <xsl:variable name="extension" select="umbraco.library:GetMedia(current()/data[@alias='AlbumImage'], 'false')/data[@alias='umbracoExtension']"/>
    <li>
    <img src="{concat(substring-before($galImage, concat('.',$extension)), concat('_thumb.',$extension))}" alt="{@nodeName}" class="project-thumbnail"/>
    <ul class="gallery-thumbnails">
    <xsl:for-each select="current()/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <xsl:element name="img">
    <xsl:attribute name="src">
    <xsl:value-of select="umbraco.library:GetMedia(current()/data[@alias='GalleryImage'], 'false')/data[@alias='umbracoFile']" />
    </xsl:attribute>
    </xsl:element>
    </li>
    </xsl:for-each>
    </ul>
    </li>
    </ul>
    </xsl:for-each>

    There's an XSLT error when I run this from the website (although the macro doesn't error when I save it).  It's something to do with the line which gets the source for the subnode images:

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

    Can anyone see where I'm going wrong?

    Thanks!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 14:33
    Lee Kelleher
    0

    Hi Dan,

    I wrote a blog post a while back about how to "safely" get images from the GetMedia call.

    http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/

    Basically, there's a problem with the "data[@alias='GalleryImage']" - either it doesn't have any data, or doesn't contain an 'umbracoFile' property? Try outputting the value directly, to debug it:

    <xmp>
        <xsl:copy-of select="umbraco.library:GetMedia(data[@alias='GalleryImage'], 0)" />
    </xmp>

    Cheers, Lee.

  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 14:47
    Dan
    0

    Thanks Lee, that's a handy blog post, so I'll make sure to implement that for my media items in future.  I'm not convinced that is the issue here though as primarily I'm using dummy data so there's not much of it there, but it's definitely all there in terms of media items.  I tried it anyhow and it's now not erroring in the render, but it's also not returning anything.  I'm very sure it must be to do with the way I'm calling "current()" in the nested list - how would it know that I mean the current nested node as opposed to the current parent node?

    My modified code for the nested lists is:

    <xsl:for-each select="current()/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <xsl:variable name="mediaId" select="number(current()/data[@alias='GalleryImage'])" />
    <xsl:if test="$mediaId &gt; 0">
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
    <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">
    <img src="{$mediaNode/data[@alias='umbracoFile']}" alt="[image]" height="{$mediaNode/data[@alias='umbracoHeight']}" width="{$mediaNode/data[@alias='umbracoWidth']}" />
    </xsl:if>
    </xsl:if>
    </li>
    </xsl:for-each>
  • dandrayne 1138 posts 2262 karma points
    Feb 05, 2010 @ 14:50
    dandrayne
    0

    What error do you get if you append

    ?umbdebugshowtrace=true

    to the URL?

    Dan

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 15:08
    Lee Kelleher
    1

    @Dan (Bristol) - The current() function is contextual.  So if you are nested within multiple for-each loops - then it will be using the current node at that point.  If you need to reference a parent node, then either store it in a variable - or use some XPath to call the "parent::node".

    In terms of debugging, just try outputting something before/after various steps - checking what the value is of variables/nodes.

    Cheers, Lee.

  • Dan 1288 posts 3921 karma points c-trib
    Feb 05, 2010 @ 15:19
    Dan
    1

    Ah-ha!  So I learn another lesson: aliases are case sensitive.  Thanks for your help folks, my original code did actually work - it's just that the alias wasn't quite in the right case.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 15:29
    Lee Kelleher
    0

    Ace, glad that you got it sorted in the end!

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft