Copied to clipboard

Flag this post as spam?

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


  • Asad Kizzie 28 posts 158 karma points
    Apr 20, 2023 @ 16:08
    Asad Kizzie
    0

    Macro that Loops Through Media Node "N" Times and Prints

    I have a working macro that asks the user to select a node from the media library and then it displays the title of each file within the node.

    I have a new need to only display the most recent 5 files within the node, not all of them.

    I'm new to XSLT and I'm having trouble with how to create this loop.

    Here's what I currently have (that displays all items):

    <xsl:template match="/">
    
    <ul>
        <!-- Loop through nodes and show all -->
            <xsl:for-each select="$documents">
        <xsl:sort select="./@createDate" order="descending" />
            <xsl:if test="number(current()/data [@alias='umbracoBytes']) &gt; 0">
                        <li><a href="{current()/data [@alias='umbracoFile']}"><xsl:value-of select="./@nodeName"/></a> 
                </li>
            </xsl:if>
            </xsl:for-each>
    </ul>
    

    Any help or suggestions?!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 21, 2023 @ 05:56
    Jan Skovgaard
    101

    Hi Asad

    While it's been a while forgive me if my memory is wrong but I think you need to write something like

    <xsl:if test="position() &lt; 6"></xsl:if> to only have top 5 recent nodes. So your example would look like this

    <xsl:template match="/">
    
    <ul>
        <!-- Loop through nodes and show all -->
            <xsl:for-each select="$documents">
        <xsl:sort select="./@createDate" order="descending" />
            <xsl:if test="position() &lt; 6">
                        <li><a href="{current()/data [@alias='umbracoFile']}"><xsl:value-of select="./@nodeName"/></a> 
                </li>
            </xsl:if>
            </xsl:for-each>
    </ul>
    

    Does this work for you?

    /Jan

  • Asad Kizzie 28 posts 158 karma points
    Apr 27, 2023 @ 15:20
    Asad Kizzie
    0

    By golly, I knew it was something simple! Thank you. This worked perfectly.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies