Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 610 posts 906 karma points
    Sep 08, 2010 @ 17:03
    Fredrik Esseen
    0

    Looping images with new schema

    Hi!

    Im trying to loop images in a folder to display with jquery.cycle but its not working.

    <?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"
     exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <xsl:value-of select="umbraco.library:RegisterJavaScriptFile('slider', '/scripts/jquery.cycle.all.js')"/>
    <style type="text/css">
    .slideshow { height: 200px; width: 600px; margin: 0px; }
    .slideshow img { }
    </style>
    <xsl:variable name="images" select="number(1092)"/>
    <div class="slideshow">
      <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($images, true())"/>
       <xsl:copy-of select="$mediaItems/Image"/>
       <xsl:for-each select="$mediaItems/Folder/Image">
        <xsl:variable name="picFile" select="umbracoFile"/>
            <img>
                 <xsl:attribute name="src"><xsl:value-of select="$picFile"/></xsl:attribute> 
                       </img>
     </xsl:for-each>&nbsp;
    </div>
    </xsl:template>
    </xsl:stylesheet>

    What is the problem?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 08, 2010 @ 17:58
    Kim Andersen
    0

    Hi froad

    That depends. Which version are you running? 4.5 or 4.5.X?

    If you are usign v4.5 the above code should actually work if the item with id 1092 is of the type "Folder", and you want to display items of the type "Image" from inside that folder. (I just tried this and it worked)

    The code would work because there was a small bug in the XML schema in v4.5.

    If you are using v4.5.X I'm quite sure that you can change your for-each to this:

    <xsl:for-each select="$mediaItems/Image">

    Haven't tested it though, but try giving it a shot. Otherwise it's a good idea to wrap your $mediaItems inside a textarea, to see the XML that your are working with like this:

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

    /Kim A

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 08, 2010 @ 18:07
    Kim Andersen
    0

    Okay, I have just tested the code I posted before, and it does work. So by changing your for-each to this:

    <xsl:for-each select="$mediaItems/Image">

    You should get a nice set of images - if you do work with v4.5.1 or v4.5.2 :)

    /Kim A

  • Fredrik Esseen 610 posts 906 karma points
    Sep 09, 2010 @ 08:38
    Fredrik Esseen
    0

    That sounds all logical but I STILL doesnt get the for-each to trigger.

    The xml looks like this :

    <node id="1092" version="01da2cb0-745f-4637-bb6e-bc3ff924286f" parentID="1042" level="2" writerID="0" nodeType="1031" template="0" sortOrder="1" createDate="2010-09-08T16:21:20" updateDate="2010-09-08T16:21:35" nodeName="Rullande bilder pÄ startsidan" urlName="rullandebilderpÄstartsidan" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1042,1092">
     <data alias="contents" />
     <data alias="uploadFiles" />
     <node id="1093" version="5b3c0526-0d25-4c8c-9958-dee0c9f6c0e1" parentID="1092" level="3" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2010-09-08T16:22:27" updateDate="2010-09-08T16:22:40" nodeName="Bussar.jpg" urlName="bussar.jpg" writerName="Administrator" nodeTypeAlias="Image" path="-1,1042,1092,1093">
     <data alias="umbracoFile">/media/1093/Bussar.jpg</data>
     <data alias="umbracoWidth">687</data>
     <data alias="umbracoHeight">133</data>
     <data alias="umbracoBytes">57842</data>
     <data alias="umbracoExtension">jpg</data>
     </node>
    </node>

    Thx for taking your time!

  • Fredrik Esseen 610 posts 906 karma points
    Sep 09, 2010 @ 08:48
    Fredrik Esseen
    0

    Im using 4.5.2 by the way.

  • Rik Helsen 670 posts 873 karma points
    Sep 09, 2010 @ 09:43
    Rik Helsen
    0

    I'm using this to loop through all images in a folder in the media section:


    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <xsl:if test="$currentPage/galleryalbum &gt; 0">
    <ul>
    <xsl:variable name="images" select="umbraco.library:GetMedia($currentPage/galleryalbum, 1)" />
    <xsl:if test="count($images/*) &gt; 0">
    <xsl:for-each select="$images/*">
    <li>
    <a href="#">
    <img src="{umbracoFile}"></img>
    </a>
    </li>
    </xsl:for-each>
    </xsl:if>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 09, 2010 @ 10:38
    Kim Andersen
    0

    Hi again froad.

    The XML that you provided above is not the new schema. That's the old one from v4.

    If you are using the old XML schema, you need to change the XSLT.

    Try something like this:

    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($images, true())"/>
       
    <xsl:for-each select="$mediaItems/node">
       
    <xsl:variable name="picFile" select="./data[@alias='umbracoFile']"/>
           
    <img>
                 
    <xsl:attribute name="src"><xsl:value-of select="$picFile"/></xsl:attribute>  
                       
    </img>
     
    </xsl:for-each>

    /Kim A

  • Fredrik Esseen 610 posts 906 karma points
    Sep 09, 2010 @ 10:46
    Fredrik Esseen
    0

    I noticed that the UmbracoSettings file was incorrect!

    Of some reason that was an old version. I updated the file and for a moment the whole website went beserk :)

    Txh for all your help!

    Hopefully things will work better now :)

  • Fredrik Esseen 610 posts 906 karma points
    Sep 09, 2010 @ 10:52
    Fredrik Esseen
    0

    One more thing..

    I updated my Topnavigation xslt and now my topmenu doesnt work...

    <?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"
     exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" omit-xml-declaration="yes" />
    <xsl:param name="currentPage"/>
    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>
    <xsl:template match="/">
    <ul class="sf-menu">
    <xsl:choose>
     <xsl:when test="$currentPage/@id='1066'"> 
         <li id="IsSelected">
         <a href="{umbraco.library:NiceUrl('1066')}">Hem</a>
         </li>
         <li>
         <img src="/images/separator.jpg" />
         </li>
       </xsl:when>
       <xsl:otherwise>
         <li>
          <a href="{umbraco.library:NiceUrl('1066')}">Hem</a>
        
         </li>
         <li>
         <img src="/images/separator.jpg" />
         </li>
       </xsl:otherwise>
      </xsl:choose>
    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc] [@level=$level]/node [string(umbracoNaviHide) != '1']">
    <xsl:choose>
    <xsl:when test="$currentPage/@id=@id or $currentPage/ancestor-or-self::*[@isDoc]/@id=@id"> 
    <li id="IsSelected">
     <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/>
     </a>
     <xsl:variable name="children" select="umbraco.library:GetXmlNodeById(@id)/node"/>
     
               <xsl:if test="count($children) > 0"> 
      <ul>
                  <xsl:for-each select="./node [string(umbracoNaviHide) != '1']">
       <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
         <xsl:value-of select="@nodeName"/>
        </a>
       </li>
      </xsl:for-each>
      </ul>
     </xsl:if>
    </li> 
    </xsl:when>
    <xsl:otherwise>
    <li>
     <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/>
     </a>
     <xsl:variable name="children" select="umbraco.library:GetXmlNodeById(@id)/node"/>
     <!--<xsl:if test="@id != '1140'">-->
               <xsl:if test="count($children) > 0">
      <ul>
                  <xsl:for-each select="./node [string(umbracoNaviHide) != '1']">
       <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
         <xsl:value-of select="@nodeName"/>
        </a>
       </li>
      </xsl:for-each>
      </ul>
               </xsl:if>
     <!--</xsl:if>-->
    </li>
    </xsl:otherwise>
    </xsl:choose>
        
     
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 09, 2010 @ 17:21
    Kim Andersen
    0

    Okay so the problem about the looping through the images is solved now?

    About your top navigation, try changing all the places where you have this:

     node 

    to this:

    *[@isDoc]

    In exaple change this:

    ./node [string(umbracoNaviHide) != '1']

    to this:

    ./*[@isDoc][string(umbracoNaviHide) != '1']

    In the new XML schema, there are no tags called <node>, like in the old schema, so this is probably why your navigation doesn't work.

    /Kim A

  • Fredrik Esseen 610 posts 906 karma points
    Sep 10, 2010 @ 08:01
    Fredrik Esseen
    0

    Yes it s solved. I was so sute that the umbracosettings.config was right since this was a fresh installation. I have no clue how an old version could have been uploaded.

    Thank you sooo much for your help!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 10, 2010 @ 17:36
    Kim Andersen
    0

    You are very welcome froad. Have a nice weekend :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft