Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 21:49
    MartinB
    0

    Pick 3 random images from a Media folder

    Hi there

    This is not too intuitive for me, so i hope some of you are able to help.

    I've made a media folder containing 9 images. I need to fecth 3 of those images for my master template on each page refresh.

    In the forums i found a nice xslt to pick any number of random images from a mediafolder. My only problem is that i dont know how to connect that xslt to the specific folder. I've tried to hardcode the ID, but that wont work for me.

    The xslt i found looks like this:

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:randomTools="http://www.umbraco.org/randomTools"
    exclude-result-prefixes="msxml umbraco.library msxsl randomTools">

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="maxItems" select="number(3)" />

    <xsl:template match="/">
    <xsl:variable name="mediaFolderID" select="number($currentPage/data [@alias = 'randomImage'])" />
    <xsl:if test="$mediaFolderID &gt; 0">
    <xsl:variable name="mediaID" select="umbraco.library:GetMedia($mediaFolderID, 'false')" />
    <xsl:if test="count($mediaID/node) &gt; 0">
    <xsl:for-each select="$mediaID//node">
    <xsl:sort select="randomTools:GetRandom(0,count($mediaID//node))" order="ascending" />
    <xsl:if test="position() = 1">
    <img src="{./data [@alias = 'umbracoFile']}">
    <xsl:attribute name="alt">
    <xsl:choose>
    <xsl:when test="string(./data[@alias='alttext']) != '' ">
    <xsl:value-of select="./data[@alias='alttext']" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="./@nodeName" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </img>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    <msxsl:script language="c#" implements-prefix="randomTools">
    <msxsl:assembly href="../bin/umbraco.dll"/>
    <![CDATA[
    /// <summary>
    /// Gets a random integer that falls between the specified limits
    /// </summary>
    /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param>
    /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param>
    /// <returns>A random integer within the specified range</returns>
    public static int GetRandom(int lowerLimit,int upperLimit) {
    Random r = umbraco.library.GetRandom();
    int returnedNumber = 0;
    lock (r)
    {
    returnedNumber = r.Next(lowerLimit, upperLimit);
    }
    return returnedNumber;
    }
    ]]>
    </msxsl:script>
    </xsl:stylesheet>
  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 21:50
    MartinB
    0

    Am i supposed to pass in the ID through this snippet:

    <umbraco:Macro Alias="RandomImage" runat="server"></umbraco:Macro>   

    If yes, how?

  • Tommy Poulsen 514 posts 708 karma points
    May 17, 2010 @ 22:03
    Tommy Poulsen
    0

    Hi Martin, in your source above you need a doctype property called "randomImage" of type media picker selecting the media folder.

    You could change that to a macro property as you suggest yourself if you want instead.

    >Tommy

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 22:05
    MartinB
    0

    Hi Tommy

    Thanks for your reply :)

    Being the Umbraco newb that i am, i'm not quite sure i get your point. Could you be more specific?

    Thanks in advance!

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 22:07
    MartinB
    0

    The only thing i did was to make a "Banners" image folder in the media section and then made the xslt with a macro.

    where do i go from there? Should i make a content type or something similar?

  • Tommy Poulsen 514 posts 708 karma points
    May 17, 2010 @ 22:20
    Tommy Poulsen
    0

    To make the macro work as it is you need to:

    1. Change your document type of the node (or make a new document type) to include a property called "randomImage" of type media picker

    2. In your content node, using the doctype of 1), select the media folder in the "randomImage" property

    >Tommy

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 22:43
    MartinB
    0

    Hi again Tommy

    I should note that i'm very grateful that you're trying to help me. I hope you can tolerate my stupid questions, but this specific task is hard for me to grasp :)

    anyway: I made a property for my textpage under "content" called RandomImages as alias and picked the folder as you suggested above. When i try to write the macro in my master or the textpage master i just get blank content. In my page source there's nothing but the div container?

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 22:47
    MartinB
    0

    oh, and im using this macro call:

     

    <umbraco:Macro Alias="RandomImage" runat="server"></umbraco:Macro>

  • Tommy Poulsen 514 posts 708 karma points
    May 17, 2010 @ 23:27
    Tommy Poulsen
    0

    sure, no problem.

    Please validate that your macro and property names are correctly named and cased.

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 23:34
    MartinB
    0

    Ok, so:

    · My Property is called "Random Image" and has an alias of "randomImage" - type Media Picker

    · On my master template i use the following macro: <umbraco:Macro Alias="randomImage" runat="server"></umbraco:Macro>

     

    It seems like this variable isn't recieving data for some peculiar reason:

     <xsl:variable name="mediaFolderID" select="number($currentPage/data [@alias = 'randomImage'])" />

  • MartinB 411 posts 512 karma points
    May 17, 2010 @ 23:41
    MartinB
    0

    I just tried making a new folder called "test" which contains 6 images and now i get this:

    Error parsing XSLT file: \xslt\RandomImage.xslt

    When i use the folder "Banners" with 9 images, it doesn't output anything :/ ?

  • Kevin Farrow 46 posts 67 karma points
    May 17, 2010 @ 23:58
    Kevin Farrow
    0

    Not sure if this will help but...

    I had a similar problem where I had renamed the property after adding pages e.g. if you had originally named the property 'RandomImage', created a new page, and then renamed the property 'propertyImage' i.e. changed the case of the first letter.

    The cached name for the property was still called 'RandomImage' for those pages I had already created and my XSLT couldn't find the property (case sensitive).

    To fix I had to republish the entire site to fix it.

    Right click on the Content node and select 'Republish entire site' from the menu.

    Kevin

  • MartinB 411 posts 512 karma points
    May 18, 2010 @ 00:05
    MartinB
    0

    Sorry Kevin

    That made no difference. The pages where i selected the "Banners" folder are still not outputting anything and the page where i selected my "test" folder is still giving me: Error parsing XSLT file: \xslt\RandomImage.xslt

    I've tried a couple of other xslt files around the forum and through nibble and i get errors on all of them more or less :/

  • Kevin Farrow 46 posts 67 karma points
    May 18, 2010 @ 02:19
    Kevin Farrow
    0

    You could try the following:

    In your template use the following code:

    <umbraco:Macro MediaFolder="[#randomImage]" Alias="randomImage" runat="server"></umbraco:Macro>

    Note: using #randomImage (hash sign in front of the property name) will use the value of the property

    In your XSLT replace the following:

    <xsl:variable name="mediaFolderID" select="number($currentPage/data [@alias = 'randomImage'])" />

    with

    <xsl:variable name="mediaFolderID" select="/macro/MediaFolder" />

    then you need to add a parameter to the 'Parameters' tab in the Macro definition for randomImage:

    Alias: MediaFolder
    Name : Media folder
    Type : number

    and make sure you check the 'Show' checkbox

    Kevin

  • MartinB 411 posts 512 karma points
    May 18, 2010 @ 17:55
    MartinB
    0

    Hi Kevin

    Thank you very much for your effort. Unfortunately i still get the same error msg or nothing at all.

    I just tried the change the casing of the alias and now i get the parsing error on the pages that use "Banners" folder, but not the pages that uses the "test" folder. Very peculiar indeed.

    Is there some way i can test where the chain falls off?

  • MartinB 411 posts 512 karma points
    May 18, 2010 @ 18:23
    MartinB
    0

    Ok, this might have somthing to do with my problem?

    http://img412.imageshack.us/i/foldersm.jpg/

    That's my media folder, and i dont have the "Banners" nor the "Test" folder that i have in Umbraco backoffice, instead if have a folder for every single image, in which there also lies a thumbnail of each image.

    Or is it supposed to do it like that? :/

  • Tommy Poulsen 514 posts 708 karma points
    May 18, 2010 @ 19:20
    Tommy Poulsen
    0

    Hi Martin - what-s your current setup - and how does your randomImage xslt look like?

  • MartinB 411 posts 512 karma points
    May 18, 2010 @ 22:42
    MartinB
    0

    Hi Tommy

    I'm using the vistaDB solution on a local host install of the newest Umbraco system (4.0.3 i think?)

    My macro call from my master template now looks like this (after taking Kevins advice):

    <umbraco:Macro MediaFolder="[#RandomImage]" Alias="RandomImage" runat="server"></umbraco:Macro>

    And my xslt now look like this, also in regard to Kevins advice:

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:randomTools="http://www.umbraco.org/randomTools"
    exclude-result-prefixes="msxml umbraco.library msxsl randomTools">

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="maxItems" select="number(6)" />

    <xsl:template match="/">
    <xsl:variable name="mediaFolderID" select="/macro/MediaFolder" />
    <xsl:if test="$mediaFolderID &gt; 0">
    <xsl:variable name="mediaID" select="umbraco.library:GetMedia($mediaFolderID, 'false')" />
    <xsl:if test="count($mediaID/node) &gt; 0">
    <xsl:for-each select="$mediaID//node">
    <xsl:sort select="randomTools:GetRandom(0,count($mediaID//node))" order="ascending" />
    <xsl:if test="position() = 1">
    <img src="{./data [@alias = 'umbracoFile']}">
    <xsl:attribute name="alt">
    <xsl:choose>
    <xsl:when test="string(./data[@alias='alttext']) != '' ">
    <xsl:value-of select="./data[@alias='alttext']" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="./@nodeName" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </img>
    <a>
    <xsl:attribute name="title">
    <xsl:text>Find out more ...</xsl:text>
    </xsl:attribute>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(./data[@alias = 'internalUrl'])"/>
    </xsl:attribute>
    <xsl:text>Find out more ...</xsl:text>
    </a>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    <msxsl:script language="c#" implements-prefix="randomTools">
    <msxsl:assembly href="../bin/umbraco.dll"/>
    <![CDATA[
    /// <summary>
    /// Gets a random integer that falls between the specified limits
    /// </summary>
    /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param>
    /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param>
    /// <returns>A random integer within the specified range</returns>
    public static int GetRandom(int lowerLimit,int upperLimit) {
    Random r = umbraco.library.GetRandom();
    int returnedNumber = 0;
    lock (r)
    {
    returnedNumber = r.Next(lowerLimit, upperLimit);
    }
    return returnedNumber;
    }
    ]]>
    </msxsl:script>
    </xsl:stylesheet>

    Again, in my media section i have two folders: "Banners" and "test". If i pick the "Test" folder on some of my pages i get no output, but if i choose the "Banners" folder i get a parsing error (displayed earlier in this post).

    I'm really interested in what that parsing error consists of. I've even checked the casing of all my aliases regarding this randomImage xslt and i can't find any valid reason as to why it keeps failing or outputting nothing. But as i said, i dont see my two folders if i access the media folder through explorer/stifinder.

  • Tommy Poulsen 514 posts 708 karma points
    May 18, 2010 @ 23:08
    Tommy Poulsen
    0

    Hi Martin,

    there appears to be a problem with this line:

    <xsl:value-of select="umbraco.library:NiceUrl(./data[@alias = 'internalUrl'])"/>

    Apparently the

    ./data[@alias = 'internalUrl']

    part does not produce a valid node id

    >Tommy

     

  • MartinB 411 posts 512 karma points
    May 19, 2010 @ 21:20
    MartinB
    0

    Hi Tommy

    Ok, that could be a step in the right direction, I just don't know what to do with that knowledge?

    What could i try instead?

  • Tommy Poulsen 514 posts 708 karma points
    May 19, 2010 @ 21:25
    Tommy Poulsen
    0

    You have to make sure that the property of your doctype called "internalUrl" is actually a node id. What does your internalUrl property contain?

  • MartinB 411 posts 512 karma points
    May 19, 2010 @ 21:46
    MartinB
    0

    Well it doesn't exist, i actually just copied the main setup of this xslt file from someone else in here.

    But maybe i should make it instead of deleting it as i can see that i can a link on each img, but what sort of doctype would that be?

  • MartinB 411 posts 512 karma points
    May 19, 2010 @ 21:47
    MartinB
    0

    can have a link was what i meant

  • Tommy Poulsen 514 posts 708 karma points
    May 19, 2010 @ 21:54
    Tommy Poulsen
    0

    probably a contentPicker. It's used for a <a> tag as a link - but you could start by commenting out the <a> ... </a> part in your xslt and see if you can get the rest working.

  • MartinB 411 posts 512 karma points
    May 19, 2010 @ 22:24
    MartinB
    0

    Will do!

    Thanks for your help thus far, i apreciate it a lot!

  • MartinB 411 posts 512 karma points
    May 19, 2010 @ 22:48
    MartinB
    0

    Hi again.

    That didn't help, not even if i remove the whole <a> section.

    I just tried this xslt, wich i think the randomImage xslt is build from, and there i have no problem getting the <li>'s if a page has subpages. Is there any way to rewrite this to spit out a random number of images from a folder instead?

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:randomTools="http://www.umbraco.org/randomTools"
    exclude-result-prefixes="msxml umbraco.library msxsl randomTools">

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="maxItems" select="number(8)" />

    <xsl:template match="/">
    <xsl:for-each select="$currentPage//node">
    <xsl:sort select="randomTools:GetRandom(0,count($currentPage//node))" order="ascending" />
    <xsl:if test="position() &lt;= $maxItems">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
    </xsl:attribute>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:if>
    </xsl:for-each>
    </xsl:template>

    <msxsl:script language="c#" implements-prefix="randomTools">
    <msxsl:assembly href="../bin/umbraco.dll"/>
    <![CDATA[
    /// <summary>
    /// Gets a random integer that falls between the specified limits
    /// </summary>
    /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param>
    /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param>
    /// <returns>A random integer within the specified range</returns>
    public static int GetRandom(int lowerLimit,int upperLimit) {
    Random r = umbraco.library.GetRandom();
    int returnedNumber = 0;
    lock (r)
    {
    returnedNumber = r.Next(lowerLimit, upperLimit);
    }
    return returnedNumber;
    }
    ]]>
    </msxsl:script>
    </xsl:stylesheet>

  • Tommy Poulsen 514 posts 708 karma points
    May 19, 2010 @ 23:05
    Tommy Poulsen
    0

    what do you get out now - a fixed amount of random images? And you want a random number of images?

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 18:01
    MartinB
    0

    right now it outputs <li> tags containing my subpages, if the current page has subpages.

    So the whole pick a folder and show images from it is missing, and yes i would very much like a random number of images.

  • Tommy Poulsen 514 posts 708 karma points
    May 20, 2010 @ 18:40
    Tommy Poulsen
    0

    a random number of fixed order images, or a fixed number of random order images ?

  • Tommy Poulsen 514 posts 708 karma points
    May 20, 2010 @ 18:43
    Tommy Poulsen
    0

    above question was: what are you looking for...

     

    The two options require quite different solutions

  • Tommy Poulsen 514 posts 708 karma points
    May 20, 2010 @ 18:58
    Tommy Poulsen
    1

    Hi Martin, now I read your original post, and I see you want e.g. 3 random images shown.

     

    This works for me as a macro with parameter MediaFolder (alias MediaFolder) type mediaCurrent. When inserting the macro you select the media folder:

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:randomTools="http://www.umbraco.org/randomTools"
        exclude-result-prefixes="msxml umbraco.library msxsl randomTools">

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

      <xsl:param name="currentPage"/>
           
      <xsl:variable name="maxItems" select="number(6)" />

      <xsl:template match="/">
        <xsl:variable name="mediaFolderID" select="/macro/MediaFolder/node/@id" />
        x<xsl:if test="$mediaFolderID > 0">
            y<xsl:variable name="mediaID" select="umbraco.library:GetMedia($mediaFolderID, 'false')" />
            <xsl:if test="count($mediaID/node) &gt; 0">
              <xsl:for-each select="$mediaID//node">
                <xsl:sort select="randomTools:GetRandom(0,count($mediaID//node))" order="ascending" />
                <xsl:if test="position() &lt;= $maxItems">
                  <img src="{./data [@alias = 'umbracoFile']}">
                    <xsl:attribute name="alt">
                      <xsl:choose>
                        <xsl:when test="string(./data[@alias='alttext']) != '' ">
                          <xsl:value-of select="./data[@alias='alttext']" />
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:value-of select="./@nodeName" />
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:attribute>
                  </img>
                  <a>
                    <xsl:attribute name="title">
                      <xsl:text>Find out more ...</xsl:text>
                    </xsl:attribute>
                          a<xsl:value-of select="./data[@alias = 'internalUrl']"/>b
                    <xsl:text>Find out more ...</xsl:text>
                  </a>
                </xsl:if>
    a<xsl:value-of select="./data[@alias = 'internalUrl']"/>b
              </xsl:for-each>
            </xsl:if>
         </xsl:if>
      </xsl:template>

      <msxsl:script language="c#" implements-prefix="randomTools">
        <msxsl:assembly href="../bin/umbraco.dll"/>
        <![CDATA[
            /// <summary>
            /// Gets a random integer that falls between the specified limits
            /// </summary>
            /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param>
            /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param>
            /// <returns>A random integer within the specified range</returns>
            public static int GetRandom(int lowerLimit,int upperLimit) {
                Random r = umbraco.library.GetRandom();
                int returnedNumber = 0;
                lock (r)
                {
                    returnedNumber = r.Next(lowerLimit, upperLimit);
                }
                return returnedNumber;
            }
        ]]>
      </msxsl:script>
    </xsl:stylesheet>

     

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 20:03
    MartinB
    0

    Hi Tommy

    Thank you for your reply. I have one silly question before trying this. How and where do i specify the medicaCurrent type? That might as well have been the problem all along?

    Thanks in advance

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 20:06
    MartinB
    0

    Nevermind, i found it ^^

    i'll try it right away

  • Tommy Poulsen 514 posts 708 karma points
    May 20, 2010 @ 20:07
    Tommy Poulsen
    0

    When creating the macro, in the right panel you see two tabs called  "Macro Properties" and "Parameters". Select "Parameters" and enter a new parameter called MediaFolder as alias and name, check "Show" and select mediaCurrent in the dropdown - then click "Add" and save the macro.

     

    Then afterwards add the macro to your template using the "Add macro" button - then you will be prompted to locate a media folder.

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 20:12
    MartinB
    0

    Oh for the love of god, you're a bloody world champion.

    THAT WAS IT!!! A god damned little forgotten type.

    Seriously, you're a star. Thank you so much!

  • Tommy Poulsen 514 posts 708 karma points
    May 20, 2010 @ 20:20
    Tommy Poulsen
    0

    You're welcome - I'm glad that we worked it out.

    >Tommy

  • MartinB 411 posts 512 karma points
    May 20, 2010 @ 20:24
    MartinB
    0

    I like the way you put that. Like i did anything ^^

     

  • AlexR 39 posts 61 karma points
    May 24, 2010 @ 07:11
    AlexR
    0

    Something like this:

    <?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"
        xmlns:randomTools="http://www.umbraco.org/randomTools"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets randomTools">


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

    <xsl:param name="currentPage" />

    <xsl:variable name="source" select="/macro/source"/>

    <xsl:variable name="numberOfItems" select="/macro/numberOfItems"/>

    <msxml:script language="c#" implements-prefix="randomTools">
        <msxml:assembly href="../bin/umbraco.dll"/>
    <![CDATA[

    public static Random random = umbraco.library.GetRandom();

    public static int RandomNext()
    {
      return random.Next();
    }

    ]]>
    </msxml:script>

    <xsl:template match="/">

    <xsl:variable name="nodes" select="umbraco.library:GetXmlNodeById($source)/node[(string(data [@alias='umbracoNaviHide']) != '1') and (data[@alias='teaserImage'] &gt; 0)]" />

    <xsl:for-each select="$nodes">
    <xsl:sort select="randomTools:RandomNext()" />
      <xsl:if test="position() &lt;= $numberOfItems">
       

      </xsl:if>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

     

Please Sign in or register to post replies

Write your reply to:

Draft