Copied to clipboard

Flag this post as spam?

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


  • arviman 71 posts 92 karma points
    Jun 03, 2010 @ 00:48
    arviman
    0

    Rendering an image based on an ancestor's value

    Hi, I'm trying to display a different banner for pages that fall under a particular menu item (called 'Solution'). In other cases I want the default banner item.

    Currently, I'm trying to loop through the ancestors of the current page, check if one of them is named 'solution' and if so, set a value to a flag which I later check to render the appropriate image. However, xslt variables cannot be set once declared, nor do i see any way of checking if the value is set in the for-each loop outside the loop.

    Is there anyway I can do that?An alternative way could be to see if there are any elements returned by the condition selected in the for-each, but I'm a noob in xslt, and don't know if this can be done.

    Thanks in advance!

    <xsl:template match="/">
    <xsl:variable name="useAnotherBanner" select="0"/>
    <xsl:if test="$currentPage/@level &gt; $menuLevel">

    <xsl:for-each select="$currentPage/ancestor::node [@level = $menuLevel and string(data [@alias='umbracoNaviHide']) != '1']">
    <xsl:if test="@nodeName = 'Solutions'">
    <xsl:variable name="useAnotherBanner" select="1"/>
    </xsl:if>
    </xsl:for-each>

    <!-- render image -->
    <xsl:choose>
    <xsl:when test="$useAnotherBanner=1">
    <img src="otherBanner.jpg" runat="server"/>
    </xsl:when>
    <xsl:otherwise>
    <img src="defaultBanner.jpg" runat="server"/>
    </xsl:otherwise>
    </xsl:choose>

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

  • arviman 71 posts 92 karma points
    Jun 03, 2010 @ 01:46
    arviman
    0

    Never mind, I got it to work :-) Thought i'd share the code.


    <xsl:variable name="menuLevel" select="2"/>

    <xsl:template match="/">
    <xsl:if test="$currentPage/@level &lt;= $menuLevel">
    <!-- render image -->
    <xsl:choose>
    <xsl:when test="count($currentPage/ancestor-or-self::node [@level = $menuLevel and string(data [@alias='umbracoNaviHide']) != '1' and @nodeName = 'Solutions']) = 1">
    Alternate banner
    </xsl:when>
    <xsl:otherwise>
    Our banner
    </xsl:otherwise>
    </xsl:choose>
    </xsl:if>
    </xsl:template>
  • 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