Copied to clipboard

Flag this post as spam?

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


  • mmmoustache 50 posts 79 karma points
    Feb 03, 2012 @ 18:43
    mmmoustache
    0

    Xslt for-each loop in Umbraco 4.5.2

    Hi all,

    I'm extremely new to xslt, having only worked with Razor in Umbraco so far but I'm trying to add a new feature on a pre-razor Umbraco site. I've noticed a couple of similarly-titled posts in this forum but I don't know enough about xslt to know if I'm just posting the same problem! 

    I basically want to render a list of media items using the uComponents Multi-Node Tree Picker to create a dynamic slideshow on the homepage, something I've done several times with Razor. At this point I should say the Umbraco version I'm working with is 4.5.2 and I've been able to render a single image from a media picker property so far but I'm having an issue creating a working for-each loop to get each image in the tree picker. This is my code so far, I'm hoping/assuming I can swap the Media Picker for the Multi-Node Tree Picker, update the alias and add a for-each loop to get it working:

         <xsl:if test="$currentPage/MEDIAPICKERALIAS != ''">
             <xsl:variable name="img" select="umbraco.library:GetMedia($currentPage/MEDIAPICKERALIAS, 0)"/>
             <img src="{$img/umbracoFile}" alt="{$img/@nodeName}" />
          </xsl:if>

    Another possibility as to why nothing is rendered is that I've installed the latest uComponents on the site via the repository, could this problem be an incompatibility issue with an older Umbraco version?

    Regards,
    mmmoustache

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 03, 2012 @ 20:43
    Jan Skovgaard
    0

    Hi mmmoustache

    Since you don't get anything returned I would like you to the following to see what the mediapickeralias is in fact returning (it's been a while since I've used the MNTP, so can't remember what is returned from the top of my head and not currently on my own machine, so have no samples).

    What do you get if you write this out?

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

    I belive this should return a list of raw comma seperated id's that you will then need to assign to a variable where you use the umbraco.library:Split extension, which will generate output like this
    <values>
    <value>1029</value>
    <value>1030</value> 
    </values> 

    Then you will need to make a match template for the value element to fetch the image.

    But let's see what you got returned and then we'll take it from there. :)

    /Jan 

Please Sign in or register to post replies

Write your reply to:

Draft