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
    Aug 17, 2011 @ 07:30
    Chris Clarke
    0

    xsl:apply-templates Conditional Syntax

    I've got the following XSLT code which lists out the folders and their file items from a specified node.

    This all works fine but I'd like to parameterise the page and optionally filter its output by a tag value.

    Being an XLST numpty I'm stumped with the syntax for the conditional I should be putting in under the 'test=$tag' clause - can someone please help ?

    <xsl:template match="/">
         
    <!-- Root folder in Media that holds the folders to output -->
         
    <xsl:variable name="mediaRootFolderId" select="5948" />

         
    <!-- Pass in true() to get XML for all nodes below -->
         
    <xsl:variable name="mediaRootNode" select="umbraco.library:GetMedia($mediaRootFolderId, true())" />

         
    <xsl:choose>
           
    <xsl:when test="$tag">

           
    </xsl:when>

           
    <xsl:otherwise>
               
    <!-- If we didn't get an error, output Folder elements that contain Image elements -->
               
    <xsl:apply-templates select="$mediaRootNode[not(error)]/Folder[File]" >
                 
    <xsl:sort select="@nodeName"/>
               
    </xsl:apply-templates>

           
    </xsl:otherwise>
         
    </xsl:choose>

         
    </xsl:template>

       
    <!-- Template for folders -->
       
    <xsl:template match="Folder">
               
    <div class="folder">
                       
    <h2>Folder: <xsl:value-of select="@nodeName" /></h2>
                       
    <div class="images">                                
                         
    <xsl:apply-templates select="File">
                           
    <xsl:sort select="@nodeName"/>
                         
    </xsl:apply-templates>
                       
    </div>
               
    </div>
       
    </xsl:template>

       
    <!-- Template for files -->
       
    <xsl:template match="File">
          File:
    <a href="{umbracoFile}" alt="{@nodeName}" ><xsl:value-of select="@nodeName" /></a> <br/>
       
    </xsl:template>

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 17, 2011 @ 22:01
    Chriztian Steinmeier
    0

    Hi Chris,

    Could you elaborate a bit and maybe explain a specific scenario? Are you trying to only process some of the files?

    /Chriztian

  • Chris Clarke 22 posts 43 karma points
    Aug 17, 2011 @ 22:49
    Chris Clarke
    0

    Hi Chriztian,

    Thanks for the offer but I posted this problem, went away for a few hours then [as I've done before] came back & solved the problem.

    In answer to your question;
    Yes, the code lists out media folders & files and if a tag value is specified then the output is restricted to filoes with that tag.

    Chris C.

  • Frederik T 241 posts 372 karma points
    Aug 18, 2011 @ 11:24
    Frederik T
    0

    Hey, could you perhaps post your fixed code? As i have a somewhat, similar problem.

  • Chris Clarke 22 posts 43 karma points
    Aug 19, 2011 @ 00:36
    Chris Clarke
    0

    I'm afraid I didn't solve the problem - only thought I did for a while

    I posted up my 'solution' tried it out at work and realised it was never going to work.

    I've abandoned using Umbraco tags against media items, they seem to be poorly documented and the functions unreliable.

    Sorry I can't help.

    Chris C.

Please Sign in or register to post replies

Write your reply to:

Draft