Copied to clipboard

Flag this post as spam?

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


  • Jamie 35 posts 87 karma points
    Oct 07, 2012 @ 08:53
    Jamie
    0

    Prceeding - Following Siblings from Media Library ID

    I'm passing an Media folder ID via a Query string and want to print out a list of the sibling folders with links for a menu.

    I can see that thecode

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

    Gives me an XML result and I can loop that out in another XSLT file to show the images.. but for the life of me I can't get the sibling links to be shown .. have spent about 4 hours trying different variations to following-sibling / preceding-sibling syntax to get nothing. The code below looks to me like it should work but I get nothing other then the current folder name displayed.

            <xsl:param name="currentPage" />
            <xsl:param name="mediafolder" select="umbraco.library:RequestQueryString('gallery')" />

            <xsl:template match="/">
                                           
            <xsl:if test="$mediafolder !=''">
                   
                <xsl:variable name="folder" select="umbraco.library:GetMedia($mediafolder, true())" />   
               
                <textarea>
                    <xsl:copy-of select="$folder"/> !contentToKeepEmptyXMLVisible!
                </textarea>
                   
                <xsl:if test="$folder != ''">

                    <ul>
                    <xsl:for-each select="$folder/preceding-sibling::*[@nodeTypeAlias = 'Folder']">
                       
                        <li>x
                            <a href="?gallery={./@id}" class="external">
                                <xsl:value-of select="./@nodeName" />                           
                            </a>
                        </li>
                    </xsl:for-each>
                       
                    <li class="selected"><xsl:value-of select="$folder/@nodeName" /></li>

                    <xsl:for-each select="$folder/following-sibling::*[@nodeTypeAlias = 'Folder']">
                       
                        <li>
                            <a href="?gallery={./@id}" class="external">
                                <xsl:value-of select="./@nodeName" />                           
                            </a>
                        </li>
                    </xsl:for-each>
                       
                    </ul>
                </xsl:if>
                       
            </xsl:if>
               
            </xsl:template>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 07, 2012 @ 12:42
    Chriztian Steinmeier
    0

    Hi Jamie,

    The reason you can't access the siblings is that they're not present in the XML you get from GetMedia() - you only get the folder you ask for with its descendants.

    You need to grab the parent folder instead, e.g.:

    <xsl:param name="currentPage" />
    <xsl:param name="mediafolder" select="umbraco.library:RequestQueryString('gallery')" />
    <xsl:param name="galleriesFolder" select="umbraco.library:GetMedia(PARENT_FOLDER_ID, true())" />
    
    <xsl:template match="/">
        <xsl:if test="normalize-space($mediafolder)">
            <xsl:variable name="folder" select="$galleriesFolder/*[@nodeTypeAlias = 'Folder'][@id = $mediafolder]" />
            <xsl:if test="$folder">
                <ul>
                    <xsl:apply-templates select="$folder/*[@nodeTypeAlias = 'Folder']" />
                </ul>
            </xsl:if>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="@nodeTypeAlias = 'Folder'">
        <li>
            <xsl:choose>
                <xsl:when test="@id = $mediafolder">
                    <xsl:attribute name="class">selected</xsl:attribute>
                    <xsl:value-of select="@nodeName" />
                </xsl:when>
                <xsl:otherwise>
                    <a href="?gallery={@id}" class="external">
                        <xsl:value-of select="@nodeName" />
                    </a>
                </xsl:otherwise>
            </xsl:choose>
        </li>
    </xsl:template>

    /Chriztian

  • Jamie 35 posts 87 karma points
    Oct 07, 2012 @ 14:14
    Jamie
    0

    Thanks Chriztian,

    I did think about going via the parent node .. but I kind of figured the sibling functions would basically do that sort of step for me, and I couldn't see any references anywhere that confilected with what I was trying to do.

     The other reason is that generally multiple templates do my head in more then just general XSLT.
    For example I copied and pasted (yep lazy gettign you to do all my work) your code above and it gives this error.

    "Expected end of the expression, found '='. @nodeTypeAlias -->=<-- 'Folder' "

    and I'm not sure what that means. as the line I think it reffrers to looks syntaticaly correct to my eyes.

    <xsl:template match="@nodeTypeAlias = 'Folder'">

    Jamie

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 07, 2012 @ 21:58
    Chriztian Steinmeier
    0

    Hi Jamie,

    Arg, sorry about that - bad error on my part. It should read like this:

    <xsl:template match="*[@nodeTypeAlias = 'Folder']">

     

    Regarding "multiple templates" in XSLT - I did a presentation on this at Codegarden '10 called "XSLT beyond <for-each>", which demonstrates how that works ... should be able to find it on stream.umbraco.org 

    /Chriztian 

  • 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