Copied to clipboard

Flag this post as spam?

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

  • Dan 1250 posts 3745 karma points admin c-trib
    Mar 24, 2010 @ 15:01

    Get parent datatype value within loop of children


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

    Can anyone point me in the right direction?

    Thanks all

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

    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

    Parent Axis

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




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

Please Sign in or register to post replies

Write your reply to: