Copied to clipboard

Flag this post as spam?

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


  • Thomas Sørensen 5 posts 25 karma points
    Oct 27, 2010 @ 20:21
    Thomas Sørensen
    0

    Random image ??

    Hello 

     

    I am trying to create a xslt file that showes a random image from a folder.

    I have found many suggestion on the internet, but none that works in Umbraco 4.5.

    Here are what i have tried so fare.

    No matter what i try, it goes wrong.. Anyone have a hint / example ?

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


        <xsl:output method="xml" omit-xml-declaration="yes" />
        <xsl:param name="currentPage"/>
       
        <xsl:variable name="pictureFolder" select="$currentPage/ancestor-or-self::*[@level = '1']/topPictures" />

    <!-- ============================================================= -->

        <xsl:template match="/">
          
          <xsl:variable name="numNodes" select="count(umbraco.library:GetMedia($pictureFolder, 1)/node)"/>
        <xsl:variable name="random" select="floor(Exslt.ExsltMath:random() * $numNodes) + 1"/>


          <xsl:value-of select="umbraco.library:GetMedia($pictureFolder, 1)/node[position() = 0]/data"/> --
          
          <xsl:value-of select="umbraco.library:GetMedia('1071', 1)"/>
          
          <img alt="Our Banner Image">
            <xsl:attribute name="src">
                <xsl:value-of select="umbraco.library:GetMedia($pictureFolder, 1)/node [position() = $random]/data"/>
            </xsl:attribute>
        </img>
          
        </xsl:template>
        
    <!-- ============================================================= 

    <xsl:template name="GetRandomNodeID">
            <xsl:variable name="numNodes" select="count(umbraco.library:GetXmlNodeById($pictureFolder)/node)"/>
            <xsl:variable name="random" select="floor(Exslt.ExsltMath:random() * $numNodes) + 1"/>
            
              <xsl:when test="umbraco.library:GetXmlNodeById($pictureFolder)/node [position() = $random] [string(data [@alias='umbracoNaviHide']) != '1'] ">
               <xsl:value-of select="$currentPage/ancestor-or-self::node[@level = 1]//node[@nodeTypeAlias = $documentTypeAlias] [position() = $random]/@id"/>
            </xsl:if>
                
    </xsl:template>
        -->
        
    </xsl:stylesheet>

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Oct 28, 2010 @ 08:47
    Sebastiaan Janssen
    0

    At first glance that looks quite good actually, can you say what doesn't work at the moment?

    One tip: put umbraco.library:GetMedia($pictureFolder, 1) in a variable so that the query doesn't have to be done three times.

    Otherwise, I just tend to output the contents of each step and try to see what's  wrong.

  • 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