Copied to clipboard

Flag this post as spam?

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


  • Hutch White 89 posts 112 karma points
    Jun 16, 2011 @ 22:33
    Hutch White
    0

    randomTools moved? Broke?

    I've been trying to get this code working but I'm getting an error stating: Cannot find a script or an extension object associated with namespace 'http://www.umbraco.org/randomTools'. Any idea if this was moved or is it broke? Should I be using something else? Maybe it's included in the library somewhere now? Any help would be greatly appreciated! Thanks!

    This is what I get when running a debug:

    Cannot find a script or an extension object associated with namespace 'http://www.umbraco.org/randomTools'.

    Here's my XSLT:

    <?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="mediapic" select="$currentPage/pageImage"/>
    <xsl:variable name="mediaFolderID" select="1094" />
    <xsl:variable name="maxItems" select="number(25)" />
          
    <xsl:template match="/">
      
      <xsl:if test="$mediapic &gt; 0">
        <xsl:variable name="pgImg" select="umbraco.library:GetMedia($mediapic, 0)"/>
        <img class="rounded" width="241" src="{$pgImg/umbracoFile}" alt="" />
      </xsl:if>
      

      <xsl:if test="$mediaFolderID &gt; 0 and $mediapic = ''">
        <xsl:variable name="mediaID" select="umbraco.library:GetMedia($mediaFolderID, 1)" />
          <xsl:if test="count($mediaID//Image) &gt; 0">
            <xsl:for-each select="$mediaID//Image">
              <xsl:sort select="randomTools:GetRandom(0,count($mediaID//Image))" order="ascending" />
                <xsl:if test="position() = 1">
                   <img src="{umbracoFile}" alt="" width="241" class="rounded" />
                </xsl:if>
            </xsl:for-each>
          </xsl:if>
       </xsl:if>  

    <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:template>

    </xsl:stylesheet>

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 13, 2011 @ 19:48
    Lee Kelleher
    0

    Hi Hutch,

    Quick question... do you know if your website is running in Medium Trust? If so, then the <msxml:script> blocks might not work.

    Take a look at a code snippet I wrote for another old post, it might help you do the randomise function?

    http://our.umbraco.org/forum/developers/xslt/19916-Loop-through-Page-Fields?p=1#comment76207

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft