Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Nov 19, 2010 @ 03:46
    Amir Khan
    0

    Change Source of Dropdown and pull name from field value

    Hi, I have the following code i'm using for a dropdown, I can't seem to figure out how to get the name of the menu items to be pulled from the page field instead of the nodeName, i would think that "<xsl:value-of select="data [@alias = 'navigationDisplayName']"/>" would work in place of "<xsl:value-of select="@nodeName"/>" but it returns nothing. Retreiving the navigationDisplayName field works with the basic navigation prototypes though...I also can't figure out how to make the nav start at level 2 instead of the root node, is there some basic flaw in my code that I'm missing?

     

    <?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 on how deep your site map should be -->
    <xsl:variable name="maxLevelForNav" select="4"/>
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">

    <ul class="sf-menu">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
    </xsl:call-template>
    </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)">
    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level=$level &lt;= $maxLevelForNav]">

    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">

    <xsl:attribute name="class">

    <xsl:if test="position() = last()">
    <xsl:text>last</xsl:text>
    </xsl:if>
    </xsl:attribute>


    <xsl:value-of select="@nodeName"/></a>
    <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForNav]) &gt; 0">
    <ul>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="."/>
    </xsl:call-template>
    </ul>
    </xsl:if>
    </li>
    </xsl:for-each>

    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 19, 2010 @ 14:14
    Tom Fulton
    0

    Hi,

    Regarding making it start at the root, your "parent" parameter is hardcoded for level 1.  Change it to read the $level variable

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level = $level]"/> 

    As you said replacing @nodeName with ./data [@alias='navigationDisplayName'] should work.  You can try outputting the XML in a textarea to make sure that property is actually there:

    <textarea><xsl:copy-of select="."/></textarea>

     

Please Sign in or register to post replies

Write your reply to:

Draft