Copied to clipboard

Flag this post as spam?

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


  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 17:11
    Ryan Green
    0

    What am I doing wrong (probably simple solution)

    In my XSLT I want to create two variables. One for the Media Folder Id for the current page:

        <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    

    And one for the Media Folder ID for the parent page. (So if there isn't a media folder ID present, it will pull the id from the parent.

    <xsl:variable name="parentFolderId" select="number($currentPage/ancestor-or-self::mediaFolderId)" />
    

    For some reason, the parent one is not working.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 03, 2014 @ 17:31
    Dennis Aaen
    0

    Hi Ryan,

    TIf you know the nodeTypeAlias (e.g. 'Textpage') of your document type, you should use that:

     <xsl:variable name="parentFolderId" select="number($currentPage/ancestor-or-self::Textpage/mediaFolderId)"/>

    Otherwise, use the more generic:

     <xsl:variable name="parentFolderId" select="number($currentPage/ancestor-or-self::*[@isDoc]/mediaFolderId)"/>

    /Dennis

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 03, 2014 @ 17:33
    Chriztian Steinmeier
    2

    Hi Ryan,

    Sounds like you want what's referred to as the recursive value of that property (i.e., taken from the first ancestor where it's specified)?

    You can do that in one select:

    <xsl:variable name="mediaFolder" select="$currentPage/ancestor-or-self::*[normalize-space(mediaFolderId)][1]/mediaFolderId" />
    

    /Chriztian

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 17:35
    Ryan Green
    0

    @Chriztian

    When trying your code, I get this error:

    System.Xml.Xsl.XslLoadException: Prefix 'ancestor-or-self' is not defined.

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 17:36
    Ryan Green
    0

    @Dennis, this is the error I get with your code.

    System.OverflowException: Value was either too large or too small for an Int32.

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 17:37
    Ryan Green
    0

    Here is my XSLT.... Basically, what I am trying to do is Use the mediaFolderId if it is present for the current page. If not, I want it to use the one from a parent page.

        <xsl:param name="currentPage"/>
    
        <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    <xsl:variable name="mediaFolder" select="$currentPage/ancestor-or-self::*[normalize-space(mediaFolderId)][1]/mediaFolderId" />    
    
        <xsl:template match="/">
    
            <!-- Displays all images from a folder in the Media Library -->
    
    
          <xsl:choose>
        <xsl:when test="number($mediaFolder)">
            <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
                        <xsl:if test="umbracoFile !=''">
                        <img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
                        </xsl:if>
                    </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
    
            <xsl:for-each select="umbraco.library:GetMedia($mediaFolder, true())/Image">
                        <xsl:if test="umbracoFile !=''">
                        <img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
                        </xsl:if>
                    </xsl:for-each>
    
            </xsl:otherwise>
    </xsl:choose>
    
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 03, 2014 @ 17:37
    Chriztian Steinmeier
    1

    Yeah, sorry 'bout that - writing this on my phone, so had to fix a couple times :)

    Should be good now.

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 18:49
    Ryan Green
    0

    The code above is not working. I pasted your code in, but it still doesn't work. Do I have something set up wrong?

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 19:37
    Ryan Green
    0

    Got it working, I didn't change part of the code below in the Choose. Once I updated that to just mediaFolder it started working. Thanks @Chriztian

  • Ryan Green 63 posts 83 karma points
    Feb 03, 2014 @ 19:38
    Ryan Green
    0

    Just for completion. Here is the working code. Including a default media folder of "4096" if there is nothing selected in the Parent.

        <xsl:param name="currentPage"/>
    
    <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    <xsl:variable name="mediaFolder" select="$currentPage/ancestor-or-self::*[normalize-space(mediaFolderId)][1]/mediaFolderId" />
    
    <xsl:template match="/">
    
        <!-- Displays all images from a folder in the Media Library -->
    
    
      <xsl:choose>
    <xsl:when test="number($mediaFolder)">
        <xsl:for-each select="umbraco.library:GetMedia($mediaFolder, true())/Image">
                    <xsl:if test="umbracoFile !=''">
                    <img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
                    </xsl:if>
                </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    
        <xsl:for-each select="umbraco.library:GetMedia(4096, true())/Image">
                    <xsl:if test="umbracoFile !=''">
                    <img src="/{umbraco.library:UrlEncode(umbracoFile)}" class="bgM" />
                    </xsl:if>
                </xsl:for-each>
    
        </xsl:otherwise>
    

Please Sign in or register to post replies

Write your reply to:

Draft