Copied to clipboard

Flag this post as spam?

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


  • David Park 32 posts 52 karma points
    Dec 01, 2010 @ 13:10
    David Park
    0

    Get parent as well as child nodes in navigation macro

    Hi folks,

    I have a macro to allow for active states on the current page. The code is below. Currently, this displays all level 1 pages. I just want to tweak it to show the parent page (home) aswell. Can anyone please suggest a solution?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="maxLevelForSitemap" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
      
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$maxLevelForSitemap]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <xsl:choose>
        <xsl:when test="@id = $currentPage/@id">
          <a class="navactive" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
        </xsl:when>
        <xsl:otherwise>
          <a class="navinactive" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
      

    </xsl:template>

    </xsl:stylesheet>

  • Kim Andersen 1447 posts 2197 karma points MVP
    Dec 01, 2010 @ 13:38
    Kim Andersen
    0

    Hi David

    Try this:

    <xsl:variable name="homepage" select="$currentPage/ancestor-or-self::* [@level=$maxLevelForSitemap]" />

    <a href="{umbraco.library:NiceUrl($homepage/@id)}">
    <xsl:if test="$currentPage/@level='1'">
    <
    xsl:attribute name="class">navactive</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="$homepage/@nodeName" />
    </a>

    <
    xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$maxLevelForSitemap]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <xsl:choose>
        <xsl:when test="@id = $currentPage/@id">
          <a class="navactive" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
        </xsl:when>
        <xsl:otherwise>
          <a class="navinactive" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>

    /Kim A

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies