Copied to clipboard

Flag this post as spam?

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


  • bigboy 16 posts 36 karma points
    Oct 27, 2011 @ 23:30
    bigboy
    0

    Iterate a media folder with child folders

    Hi,

    i am trying to interate through a media folder with mulitple child folders in it and return all the images as a list. Here is what i have, but does not seem to work.  i have highlighted the part I suspect. 

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      
      <!-- for best results remove the lines below, and put them in the <head> of your document -->
      <!--Styles-->
      
      <!-- for best results remove the lines above, and put them in the <head> of your document -->
      
      <xsl:variable name="imageFolder" select="/macro/imageFolder" />
      <xsl:variable name="galleryTitle" select="/macro/galleryTitle" />
      <xsl:variable name="galleryDescription" select="/macro/galleryDescription" />  
      <xsl:variable name="imageFolderContents" select="umbraco.library:GetMedia($imageFolder/Folder/@id, 1 )"/>
      <div class="galleryTitle">
      <xsl:if test="string($galleryTitle) != ''">
       <h3><xsl:value-of select="umbraco.library:Replace($galleryTitle, '\r\n', '&#160;')" /></h3>
        </xsl:if>
        <xsl:if test="string($galleryDescription) != ''">
          <p><xsl:value-of select="umbraco.library:Replace($galleryDescription, '\r\n', '&#160;')" /></p>
        </xsl:if>
        </div>
      <div id="thumbs" class="navigation">
      <ul class="thumbs noscript">  


        <!--interate, please check this part-------------------------------->
       <xsl:for-each select="imageFolderContents/descendant-or-self::node [@nodeTypeAlias = 'Image']">
        <!------------------------------------------------------------------>


        <xsl:if test="string(current()/umbracoFile) != ''">
          <li>
            <class="thumb">
              <xsl:attribute name="href">
                <xsl:text>/ImageGen.ashx?image=</xsl:text>
                <xsl:value-of select="./umbracoFile" />
                <xsl:text>&amp;height=350&amp;compression=100</xsl:text>
              </xsl:attribute>
              <img alt="{current()/@nodeName}">
                <xsl:attribute name="src">
                  <xsl:text>/ImageGen.ashx?image=</xsl:text>
                  <xsl:value-of select="./umbracoFile" />
                  <xsl:text>&amp;height=75&amp;width=75&amp;compression=100</xsl:text>
                </xsl:attribute>
              </img>
            </a>
            <div class="caption">
              <div class="image-title"><xsl:value-of select="@nodeName"/></div>
              <div class="image-desc"><xsl:value-of select="galleryImageDescription"/></div>
            </div>
          </li>
        </xsl:if>
      </xsl:for-each>        
      </ul>
    </div
    <div style="clear: both;"></div>
    </xsl:template>

    </xsl:stylesheet>

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Oct 28, 2011 @ 10:26
    Dave Woestenborghs
    0

    I think you should use this code :

    <xsl:for-each select="$imageFolderContents/descendant-or-self::node [@nodeTypeAlias = 'Image']">

    You forgot the dollor sign for the variable imageFolderContents

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2011 @ 10:34
  • bigboy 16 posts 36 karma points
    Oct 28, 2011 @ 16:02
    bigboy
    0

    hi dawoe, i put in the dollar sign, but it is still not working. any further suggestion is much apppreciated. this problem has confused me for a while

  • bigboy 16 posts 36 karma points
    Oct 28, 2011 @ 20:04
    bigboy
    0

    hi rich green,

    i'm using 4.7. The method provided in your first link does not loop each folder for images. it only list the files, no matter if its image, a folder, or other types of file.

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2011 @ 23:30
  • bigboy 16 posts 36 karma points
    Oct 31, 2011 @ 19:42
    bigboy
    0

    Thanks all. After struggling for a while i finally get it working. The method is a bit dumb, but it works. 

    Hope it can help others.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:variable name="mediaFolder" select="/macro/imageFolder" />
    <xsl:variable name="galleryTitle" select="/macro/galleryTitle" />
    <xsl:variable name="galleryDescription" select="/macro/galleryDescription" />  
    <xsl:variable name="imageFolderContents" select="umbraco.library:GetMedia($mediaFolder/Folder/@id, 1 )"/>
    <div class="galleryTitle">
      <xsl:if test="string($galleryTitle) != ''">
        <h3><xsl:value-of select="umbraco.library:Replace($galleryTitle, '\r\n', '&#160;')" /></h3>
      </xsl:if>
      <xsl:if test="string($galleryDescription) != ''">
        <p><xsl:value-of select="umbraco.library:Replace($galleryDescription, '\r\n', '&#160;')" /></p>
      </xsl:if>
    </div>

    <div id="thumbs" class="navigation">
    <ul class="thumbs noscript">

    <xsl:for-each select="$imageFolderContents">  
    <xsl:call-template name="Image"/>
    </xsl:for-each>

      
    <xsl:for-each select="$imageFolderContents/Folder">
    <xsl:call-template name="Image"/>
    </xsl:for-each>

    </ul>
      
    </div
    </xsl:template>

    <xsl:template name="Image">    
    <!-- check if there are any images -->
      
    <xsl:if test="Image">
    <!-- loop through each image -->
      
    <xsl:for-each select="Image">
    <xsl:if test="string(current()/umbracoFile) != ''">
    <li>
    <class="thumb">
    <xsl:attribute name="href">
    <xsl:text>/ImageGen.ashx?image=</xsl:text>
    <xsl:value-of select="./umbracoFile" />
    <xsl:text>&amp;width=350&amp;compression=100</xsl:text>
    </xsl:attribute>
    <img alt="{current()/@nodeName}">
    <xsl:attribute name="src">
    <xsl:text>/ImageGen.ashx?image=</xsl:text>
    <xsl:value-of select="./umbracoFile" />
    <xsl:text>&amp;height=75&amp;width=75&amp;compression=100</xsl:text>
    </xsl:attribute>
    </img>
    </a>
    <div class="caption">
    <div class="image-title"><xsl:value-of select="@nodeName"/></div>
    <div class="image-desc"><xsl:value-of select="galleryImageDescription"/></div>
    <div class="download">
    <target="_blank">
    <xsl:attribute name="href">
    <xsl:text>/ImageGen.ashx?image=</xsl:text>
    <xsl:value-of select="./umbracoFile" />
    </xsl:attribute>
    <xsl:text>View Original</xsl:text>
    </a>
    </div>
    </div>
    </li>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>


    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft