Copied to clipboard

Flag this post as spam?

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


  • Dan 1243 posts 3708 karma points admin c-trib
    Mar 24, 2010 @ 15:01
    Dan
    0

    Get parent datatype value within loop of children

    Hi,

    I have a loop of child nodes.  For each one I need to go up the node structure to the parent and grab a value of a datatype, which will apply the appropriate colour to the child element.

    The XSLT loops through the children fine, but I can't seem to get the value from the parent.  It's just the syntax of the fourth line that's wrong I think.  I thought this would grab the 'data' of the 'parent' of the current (./) node, but something's not right:

    <xsl:variable name="level" select="5"/>
    <ul>
    <xsl:for-each select="$currentPage/descendant::node [@level=$level]">
    <xsl:variable name="projectColour" select="./parent/data [@alias = 'projectColour']"/>
    <li>
    <xsl:if test="$projectColour != ''">
    <xsl:attribute name="style">
    <xsl:value-of select="concat('color: #',$projectColour)" />
    </xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </li>
    </xsl:for-each>
    </ul>

    Can anyone point me in the right direction?

    Thanks all

  • Bogdan 250 posts 426 karma points
    Mar 24, 2010 @ 15:27
    Bogdan
    0

    To select the parent of a node you can use ../ e.g. to get the projectColour property from the parent do <xsl:value-of select="../data [@alias = 'projectColour']"/>

  • Rasmus Berntsen 213 posts 251 karma points c-trib
    Mar 24, 2010 @ 15:34
    Rasmus Berntsen
    1

    http://umbraco.org/documentation/books/xslt-basics/xpath-axes-and-their-shortcuts

    Parent Axis

    The parent axis allows us to see the node immediately above the node in reference.

    $currentPage/parent::node

    $currentPage/../

     

    I usually go for the "parent::node" but both should work. :)

Please Sign in or register to post replies

Write your reply to:

Draft