Copied to clipboard

Flag this post as spam?

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


  • Matt 15 posts 45 karma points
    Oct 20, 2010 @ 17:53
    Matt
    0

    Help converting 4.0 left-navigation xslt to 4.5 schema

    Hello,

    Been banging my head on the wall and thought I'd see if anyone could provide a little hand-holding.  I've gotten it to partially work, but only two levels deep.  I'm sure I'm missing something simple, but I'm still learning XSLT, so the solution is evading me.

    Here's the working 4.0 XSLT:

    <?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" exclude-result-prefixes="msxml
    umbraco.library">

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

    <xsl:param name="currentPage"/>

    <!-- update this variable to set how deep the navigation should go -->
    <xsl:variable name="maxLevelForNav" select="6"/>

    <xsl:template match="/">
    <ul><li class="selected">
    <xsl:if test="$currentPage [string(@level) = '2']">
    <h4><a href="{umbraco.library:NiceUrl($currentPage/@id)}"><xsl:value-of select="$currentPage/@nodeName"/></a></h4>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage"/>
    </xsl:call-template>
    </xsl:if>
    <xsl:if test="$currentPage [string(@level) = '3']">
    <h4><a href="{umbraco.library:NiceUrl($currentPage/../@id)}"><xsl:value-of select="$currentPage/../@nodeName"/></a></h4>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/parent::node"/>
    </xsl:call-template>
    </xsl:if>
    <xsl:if test="$currentPage [string(@level) = '4']">
    <h4><a href="{umbraco.library:NiceUrl($currentPage/../../@id)}"><xsl:value-of select="$currentPage/../../@nodeName"/></a></h4>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/parent::node/parent::node"/>
    </xsl:call-template>
    </xsl:if>
    <xsl:if test="$currentPage [string(@level) = '5']">
    <h4><a href="{umbraco.library:NiceUrl($currentPage/../../../@id)}"><xsl:value-of select="$currentPage/../../../@nodeName"/></a></h4>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/parent::node/parent::node/parent::node"/>
    </xsl:call-template>
    </xsl:if>
    </li></ul>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul class="lowest">
    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForNav and @nodeTypeAlias!='News Item' and @nodeTypeAlias!='News Listing']">
    <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:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/></a>
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias!='QBE News Item' and @level &lt;= $maxLevelForNav]) &gt; 0">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="."/>
    </xsl:call-template>
    </xsl:if>
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    And here's what I have so far for 4.5:

    <?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"/>

    <!-- update this variable to set how deep the navigation should go -->
    <xsl:variable name="maxLevelForNav" select="6"/>

    <xsl:template match="/">
    <ul><li class="selected">
        <xsl:if test="$currentPage [string(@level) = '2']">
            <h4><a href="{umbraco.library:NiceUrl($currentPage/@id)}"><xsl:value-of select="$currentPage/@nodeName"/></a></h4>
            <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="$currentPage [string(@level) = '3']">
            <h4><a href="{umbraco.library:NiceUrl($currentPage/../@id)}"><xsl:value-of select="$currentPage/../@nodeName"/></a></h4>
            <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/parent::*[@isDoc]"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="$currentPage [string(@level) = '4']">
            <h4><a href="{umbraco.library:NiceUrl($currentPage/../../@id)}"><xsl:value-of select="$currentPage/../../@nodeName"/></a></h4>
            <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/parent::*[@isDoc]/parent::*[@isDoc]"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="$currentPage [string(@level) = '5']">
            <h4><a href="{umbraco.library:NiceUrl($currentPage/../../../@id)}"><xsl:value-of select="$currentPage/../../../@nodeName"/></a></h4>
            <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/parent::*[@isDoc]/parent::*[@isDoc]/parent::*[@isDoc]"/>
            </xsl:call-template>
        </xsl:if>
    </li></ul>
    </xsl:template>

    <xsl:template name="drawNodes">
        <xsl:param name="parent"/>
        <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
            <ul class="lowest">
                <xsl:for-each select="$parent/* [@isDoc][string(./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:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                            <xsl:attribute name="class">current</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="@nodeName"/></a>
                        <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                          <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and not(self::newsItem) and not(self::newsListing) and @level &lt;= $maxLevelForNav]) &gt; 0">
                            <xsl:call-template name="drawNodes">   
                              <xsl:with-param name="parent" select="."/>   
                            </xsl:call-template>
                          </xsl:if>
                        </xsl:if>
                    </li>
                </xsl:for-each>
            </ul>
        </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 20, 2010 @ 18:45
    Jan Skovgaard
    0

    Hi Matt

    I think it's because you have this multiple places in your drawNodes template

    currentPage/ancestor-or-self::node/@id 

    I guess it should be written as

    currentPage/ancestor-or-self::*[@isDoc]/@id 

     

    Hope this helps

    /Jan

  • Matt 15 posts 45 karma points
    Oct 20, 2010 @ 23:50
    Matt
    0

    Duplicate post, please delete

Please Sign in or register to post replies

Write your reply to:

Draft