Copied to clipboard

Flag this post as spam?

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


  • Dave 16 posts 36 karma points
    Nov 06, 2010 @ 17:56
    Dave
    0

    4.5.2 Schema change help

    I have a macro that is meant to randomly select an image for a page from a folder specified as a parameter.

    The problem is that the getMedia doesn't always return a value, which it did previously.  Can anyone see what's wrong here?

    <?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:variable name="folderNodeID" select="/macro/randomImage"/>
      <xsl:variable name="debug" select="0"/>

      <xsl:template match="/">

        <xsl:if test="$debug=1">
          <xsl:comment>
            folderNodeID <xsl:value-of select="$folderNodeID"/>        
          </xsl:comment>
        </xsl:if>


        <xsl:choose>
          <xsl:when test="$folderNodeID &gt; 0">
            <xsl:variable name="randomImageNumber" select="ceiling( Exslt.ExsltMath:random() * (count(umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image) ) )"/>
            <xsl:choose>
              <xsl:when test="$randomImageNumber &gt; 0">
                <img src="{umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image[$randomImageNumber]/umbracoFile}" />  
              </xsl:when>
              <xsl:otherwise>
                <xsl:comment>folderNodeId lt= 0</xsl:comment>
                <xsl:call-template name="drawFromDefault" />
              </xsl:otherwise>
            </xsl:choose>

          </xsl:when>
          <xsl:otherwise>
            <xsl:comment>
              Folder Id was not provided.
            </xsl:comment>
            <xsl:call-template name="drawFromDefault" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

      <xsl:template name="drawFromDefault">
        <xsl:variable name="folderNodeID" select="1216"/>
        <xsl:if test="$debug=1">
          <xsl:comment>
            using default folderNodeID <xsl:value-of select="$folderNodeID"/>        
          </xsl:comment>
        </xsl:if>
        <xsl:variable name="randomImageNumber" select="ceiling( Exslt.ExsltMath:random() * (count(umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image) ) )"/>
        <xsl:if test="$randomImageNumber &gt; 0">
          <img src="{umbraco.library:GetMedia($folderNodeID, 1)/Folder/Image[$randomImageNumber]/umbracoFile}" />
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 07, 2010 @ 21:05
    Lee Kelleher
    0

    Hi Dave,

    Try removing the 'Folder' part of the XPath expression.

    <img src="{umbraco.library:GetMedia($folderNodeID, 1)/Image[$randomImageNumber]/umbracoFile}" />

    There was a bug with GetMedia in 4.5.0 that returned the documentElement, not the firstChild (which was expected behaviour). This was quickly resolved, but caused a little confusion for anyone upgrading to/from 4.5.0.

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft