Copied to clipboard

Flag this post as spam?

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


  • Chris Clarke 22 posts 43 karma points
    Oct 30, 2010 @ 08:35
    Chris Clarke
    0

    Parameter of mediaCurrent doesn't have value

    I want to pass a media folder as a parameter to an XSLT function and use it to produce an HTML list of images in that folder.

    As an XSLT newbie I've researched the examples and have;

    - A macro parameter of: Alias = MediaNode & Type = mediaCurrent

    - Added the macro to my template via the UI, set the media folder and it shows as;

    <umbraco:Macro MediaNode="1183" Alias="Sample" runat="server"></umbraco:Macro>

    The XSLT code for Sample within starts with;

    <xsl:variable name="MediaNodeId" select="/macro/MediaNode/node/@id"/>
    MediaNode: <xsl:copy-of select="/macro/MediaNode" />

    I never get a value for the media folder passed through to the XSLT but I can pass text parameters with no problem.

    Any help appreciated.      

     

     

  • Chris Koiak 700 posts 2626 karma points
    Oct 30, 2010 @ 10:21
    Chris Koiak
    0

    Try

    <xsl:variable name="MediaNodeId" select="/macro/MediaNode"/>
    MediaNode:
    <xsl:copy-of select="/macro/MediaNode" />

    Chris

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 30, 2010 @ 10:51
    Jan Skovgaard
    0

    To make the output a bit more readable you wrap the xsl:copy-of statement in Chris' sample in a <textarea></textarea>...then you can copy/paste the output to a file where it's easy to see the returned XML.

    Just at little tip.

     

    /Jan

  • pete 2 posts 22 karma points
    Oct 30, 2010 @ 12:47
    pete
    0

    Have wrapped the xsl:copy of statement in a textarea - good tip !

    It returns;

    mediaFolder: <MediaNode><Folder id="1183" version="366c8233-4c43-410b-ad10-bbaf349f32e1" parentID="-1" level="1" writerID="0" nodeType="1031" template="0" sortOrder="49" createDate="2010-10-30T08:28:43" updateDate="2010-10-30T08:28:43" nodeName="Slider Images" urlName="sliderimages" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1183"><contents /></Folder></MediaNode>

    So I am getting the media folder passed through.
    My understanding is that I need the 'media folder ID' so that I can process the images in the folder by;

    <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 1)" />
    <xsl:for-each select="$images/node">
    .....
    </xsl:for-each>

    I'm referring to the example at http://our.umbraco.org/wiki/reference/code-snippets/listfilesfrommediafolderxslt for guidance but the statement

    <xsl:param name="mediaFolderID" select="$mediaFolder/node/@id" />

    doesn't ring true (or work) for me.

    Would appreciate another clue, excuse me if I don't reply promptly it's getting late here.

    Chris C.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 30, 2010 @ 13:48
    Jan Skovgaard
    0

    Node won't match anything since you are using the new xml schema - Node is from the legacy schema so I think that is what's confusing you :-)

    Try to make a copy-of on the $images variable to see the output you get returned (can't remember the syntax as I write). You probably get one or more <image> elements returned. But have a look to be sure.

    /Jan

     

     

  • Chris Clarke 22 posts 43 karma points
    Oct 31, 2010 @ 02:28
    Chris Clarke
    0

    Hi,

    Thanks for the hints, I eventually got there and learnt a lot in the process.

    My code is now;

    <xsl:param name="currentPage"/>
    <xsl:param name="mediaFolder" select="$currentPage/sliderImages" />
    <xsl:template match="/">


    <xsl:if test="$mediaFolder!=''"> <!-- Necessary test otherwise the GetMedia(...) call throws a compiler error !!  -->
    <xsl:for-each select="umbraco.library:GetMedia($mediaFolder, 'true')/descendant-or-self::*[@nodeTypeAlias='Image']">
        <xsl:if test="./umbracoFile">
     <li>
                <img src="{./umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
     </li>
        </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>

    I was surprised to realise that this clause is necessary for the XSLT to compile;

    <xsl:if test="$mediaFolder!=''"> 

    Perhaps I'm looking at it from a .Net not an XSL point of view but I always thought IF statements were only evaluated at runtime ?

    Again - thanks

    Chris C.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 31, 2010 @ 22:07
    Chriztian Steinmeier
    0

    Hi Chris,

    The reason you need that test is because Umbraco will execute the transform upon "Save" to make sure it's a valid file. It won't, however, put anything in the macro parameters, thus making the call to GetMedia() fail.

    Here's another way to do it that's a little bit more 'XSLT'-ish, if you like:

    <xsl:param name="currentPage" />
    
    <xsl:template match="/">
        <!-- Only process sliderImages if it holds an id  -->
        <xsl:apply-templates select="$currentPage/sliderImages[normalize-space()]" />
    </xsl:template>
    
    <xsl:template match="sliderImages">
        <!-- Get contents of folder -->
        <xsl:variable name="images" select="umbraco.library:GetMedia(., true())" />
        <!-- Process all images with a specified file -->
        <xsl:apply-templates select="$images/descendant-or-self::Image[umbracoFile]" />
    </xsl:template>
    
    <xsl:template match="Image">
        <li>
            <img src="{umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
        </li>
    </xsl:template>
    

    /Chriztian 

  • Chris Clarke 22 posts 43 karma points
    Nov 05, 2010 @ 22:18
    Chris Clarke
    0

    Thank-you, I understand better now what it's trying to do.

    I've implemented your code and it works fine.
    I kind of understand the code but realise that my XSLT skills need more work.

    Thanks.

     

Please Sign in or register to post replies

Write your reply to:

Draft