Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
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']"/>
The parent axis allows us to see the node immediately above the node
I usually go for the "parent::node" but both should work. :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted