I have my navigation thats has a page called KnowHow. I would like to target this pages <li> and apply a class to it.
Thanks Dan, but still now joy.
My xslt is below
<xsl:template match="/"> <!-- Root Node --> <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" /> <!-- Homepage --> <xsl:variable name="homeNode" select="$rootNode/Home [@isDoc]" /> <ul> <li> <!-- Add the CSS class 'selected' if the homeNode ID matches our currentPage node ID --> <xsl:if test="$homeNode/@id = $currentPage/@id"> <xsl:attribute name="class"> <xsl:text>selected</xsl:text> </xsl:attribute> </xsl:if> <!--Create a link to the homepage --> <a href="{umbraco.library:NiceUrl($homeNode/@id)}"> <xsl:value-of select="$homeNode/@nodeName" /> </a> </li> <!-- For each child node of the homeNode that is a document (isDoc) and the level is 2 and the property umbracoNaviHide is NOT 1 (true/checked) --> <xsl:for-each select="$homeNode/* [@isDoc and @level = 2 and string(umbracoNaviHide) != '1']"> <li> <!-- Add the CSS class 'selected' if the currentPage or parent nodes (up the tree to the root) ID matches our current node's ID in the for each loop --> <xsl:if test="$currentPage/ancestor-or-self::* [@isDoc]/@id = current()/@id"> <xsl:attribute name="class"> <xsl:text>selected</xsl:text> </xsl:attribute> </xsl:if> <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc and @nodeName='KnowHow']"> <xsl:attribute name="class"> <xsl:text>knowhow</xsl:text> </xsl:attribute> </xsl:if> <!-- Create the link --> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /> </a> <!--DROP DOWN NAVIGATION--> <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0"> <ul> <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']"> <li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></li> </xsl:for-each> </ul> </xsl:if> </li> </xsl:for-each> </ul> </xsl:template>
If your node is actually called "KnowHow", then I don't see why this wouldn't work. I agree with Dirk, though, that basing anything in XSLT on the name of a specific node is very fragile, since the value can so easily change.
I assume what you are trying to achieve is a different styling of that specific section in the Menu? Does the KnowHow section by any chance contain nodes of a different doctype than the other sections? In that case you could find a more robust way to match that section in the XPath.
Be aware that the "knowhow" class will override the "selected" class if both statements are valid for the given node. This might be a more robust way to do it:
You're still depending on the node name, since that forms the bases of the @urlName, but the @urlName can be "frozen" via an umbracoUrlName property on the page to make it a bit more bulletproof. And you'll end up with a <li class="knowhow selected"/> and can style according to both properties.
Get nodeName in XSLT
Hi Im trying to pick out a nodeName and apply a class to it without any success.
Ive checked for upper and lowercase differences.
Any help would be grateful.
Martin
Just to be sure, you are going for the actual node name, and not the nodeTypeAlias? Otherwise it'd simply be:
If it's the node name you are going for, can you do a dump of the output and paste it in this thread? E.g.:
Sounds ok to me, have you tried...
(BTW: you wouldn't want to select a page based on the name in the content tree, it might change and your xslt will *break*)
Cheers,
/Dirk
Sorry I should maybe explain a bit more.
I have my navigation thats has a page called KnowHow. I would like to target this pages <li> and apply a class to it.
Thanks Dan, but still now joy.
My xslt is below
If your node is actually called "KnowHow", then I don't see why this wouldn't work. I agree with Dirk, though, that basing anything in XSLT on the name of a specific node is very fragile, since the value can so easily change.
I assume what you are trying to achieve is a different styling of that specific section in the Menu? Does the KnowHow section by any chance contain nodes of a different doctype than the other sections? In that case you could find a more robust way to match that section in the XPath.
Be aware that the "knowhow" class will override the "selected" class if both statements are valid for the given node. This might be a more robust way to do it:
You're still depending on the node name, since that forms the bases of the @urlName, but the @urlName can be "frozen" via an umbracoUrlName property on the page to make it a bit more bulletproof. And you'll end up with a <li class="knowhow selected"/> and can style according to both properties.
Thanks Dan, that worked a treat.
is working on a reply...