|
|
 Rank: Newbie
Joined: 5/26/2008 Posts: 21 Location: Denmark
|
Hi I have a problem understanding what I'm doing wrong. I am trying to display my links as Selected for a submenu, when I am at them, but can't seem to get it to work :/ I got this code in my XSLT: Code: <ul> <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <xsl:if test="$currentPage/@id=current()/@id"> <xsl:attribute name="class">Selected</xsl:attribute> </xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}"> <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute> <xsl:value-of select="@nodeName" /> </a>
</li>
</xsl:for-each> </ul>
I guess its something with the way I refer to the current subpage, in the if test, but I can't figure out how to do it correctly. Many thanks for any help :) /Steven
|
|
 Rank: Fanatic
Joined: 9/27/2007 Posts: 403 Location: Belgium
|
Hi, Can't really figure out what exactly you're doing wrong, but here's the script I use in a similar situation (Navigation on my corporate site) Code: <ul> <xsl:for-each select="$currentPage/ancestor-or-self::node [@level = 1]/node [string(data [@alias = 'umbracoNaviHide']) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <xsl:attribute name="class">current</xsl:attribute> </xsl:if> <span><xsl:value-of select="@nodeName"/></span> </a> </li> </xsl:for-each> </ul>
Hope that helps. If you really like to know what you did 'wrong', I suggest you write out the 2 expressions you're evaluating: $currentPage/@id and current()/@id in each <li> element. Maybe that will give you a hint about the 'mistake'. Regards, /Dirk
level 1 certified - umbraco blog at netaddicts.be
|
|
 Rank: Newbie
Joined: 5/26/2008 Posts: 21 Location: Denmark
|
thx Dirk! afraid it only resulted in my sub pages not being displayed, but my main pages instead I must admit I am totally new to XSLT and don't have a good overview of how to refer to the different levels, yet..
|
|
 Rank: Fanatic
Joined: 9/27/2007 Posts: 403 Location: Belgium
|
It's always a good idea to write out the complete xml structure of $currentPage. <!--xsl:copy-of select="$currentPage"/--> Of course, uncomment the line if you're in production environment!! Also, have a look at this tool (Great resource for non xslt guru's - being one myself) Grab the output of <xsl:copy-of select="$currentPage" /> and paste it in the editor and start writing that piece of xslt you need. Good luck. Regards, /Dirk
level 1 certified - umbraco blog at netaddicts.be
|
|
 Rank: Newbie
Joined: 5/26/2008 Posts: 21 Location: Denmark
|
Okay thanks :) I'll give at go!
|
|
 Rank: Newbie
Joined: 5/26/2008 Posts: 21 Location: Denmark
|
I found my mistake, and it wasn't the if test. It was the Code: <ul> <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <xsl:attribute name="class">Selected</xsl:attribute> </xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}"> <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute> <xsl:value-of select="@nodeName" /> </a>
</li>
</xsl:for-each> </ul>
I had just forgotten to give my <ul> an identifier like <ul id="navi">, to match my css.. Well hope it can help anyone else who might be as forgetful as me :P
|
|
|
Guest |