Copied to clipboard

Flag this post as spam?

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


  • Kenny Burns 173 posts 305 karma points
    Dec 02, 2011 @ 15:43
    Kenny Burns
    0

    Newbie Image Issue

    Hi Guys,

    Hope someone is able to help - i am sure it will be an easy issue but i am pulling my hair out! I have a macro that ou can assign to a page that displays an image. It seems to work fine. HOWEVER - all subpages are showing the parent page image when i have not assigned an image to any of these subpages.

    Code:<?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="mediaId" select="/macro/imageId"/>
    <xsl:variable name="cropName" select="/macro/cropName"/>
    <xsl:variable name="imageClass" select="/macro/imageClass"/>
    <xsl:variable name="altTag" select="/macro/altTag"/>

    <xsl:template match="/">



    <xsl:if test="$mediaId &gt; 0">

    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, 0)" />

    <xsl:choose>
    <xsl:when test="$altTag != ''">

    <img src="{$media/umbracoFile}" class="{$imageClass}" alt="{$altTag}" />
    <!--<img src="{$media/crops//crop [@name =$cropName]/@url}" class="{$imageClass}" alt="{$altTag}" />-->
    </xsl:when>
    <xsl:otherwise>
    <img src="{$media/crops//crop [@name =$cropName]/@url}" class="{$imageClass}" alt="{$media/altTag}" />
    </xsl:otherwise>
    </xsl:choose>




    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

     

    Any help would be much appreciated!!

    Kenny

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 02, 2011 @ 15:53
    Tom Fulton
    0

    Hi Kenny,

    How are you passing the mediaId value from your template to your macro?  I am guessing you're using Macro Parameter Syntax and that you're using [$propertyAlias] instead of [#propertyAlias].  The $ one uses a recursive value, meaning if the value isn't defined on the current node, it will take the value from the first parent that has it defined.  So if you don't want this behavior, try using # instead.

    Hope this helps,
    Tom

  • Kenny Burns 173 posts 305 karma points
    Dec 02, 2011 @ 16:00
    Kenny Burns
    0

    Tom,

    Every day is a school day!! I never knew about this # tag and that has done the trick!! So using $ on a template as opposed to the # takes the value from the first parent that has it defined? I am assuming the $ signs in the macros are different?

    You my friend are a legend!

    Thanks a lot -

    Kenny

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 02, 2011 @ 16:02
    Tom Fulton
    0

    You got it, see that wiki link for details -- yes, $ takes the value from the first parent that has it defined, just like the way the recursive option works on the umbraco:Item tag.  And yes, $ inside the XSLT macro denotes a variable, something different :)

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft