Copied to clipboard

Flag this post as spam?

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


  • Jose 5 posts 25 karma points
    Jun 08, 2010 @ 22:20
    Jose
    0

    How to handle multilingual menu items

    Hi folks,

     I have multilingual site approach and I am using the bellow structure.

    Content

      - English
          Page1 

    - Spanish
         Page 1

    I want integrate a top navigation menu, the doctype used has a property showinNav to handle if the item will showed in the menu and works well, but now my question is how to handle the menu for multilingual, when is loaded  a page shows all the menu items icluding all the language items.

    I hope you can help me. 

     

    Thank you,
    José

     

  • Bert 128 posts 251 karma points
    Jun 08, 2010 @ 22:25
    Bert
    0
    select="$currentPage/ancestor-or-self::node [@level=$level]/node 
    [string(data [@alias='umbracoNaviHide']) != '1']"

    selects the nodes based on the $level variable. You should select the nodes from lvl 1

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>
  • Jose 5 posts 25 karma points
    Jun 08, 2010 @ 22:51
    Jose
    0

    Hello Bert,

    Thank you for your answer, I have this XSLT, where the code should go?

    <?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 on how deep your navigation should be -->
    <xsl:variable name="maxLevel" select="5"/>
    <xsl:variable name="menuSection" select="//PL_MenuSection" />

    <xsl:template match="/">

    <ul id="{$menuSection}">
    <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='naviHide']) != '1' and @level &lt;= $maxLevel)  ]">
       
        <xsl:variable name="class" >
            <xsl:choose>
                <xsl:when test="@level = 2" ><xsl:value-of select="$menuSection" />_Title</xsl:when>
            </xsl:choose>
        </xsl:variable>

    <li class="{$class}" >
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a> 
    <xsl:if test="count(./node [string(./data [@alias='naviHide']) != '1' and @level &lt;= $maxLevel]) &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>

    José

     

  • Bert 128 posts 251 karma points
    Jun 09, 2010 @ 01:06
    Bert
    0

    Can't test this atm but it should work:

    play a bit with the startlvl variable to fit your structure and needs

    <?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 on what depth your navigation should start -->
    <xsl:variable name="startLevel" select="2"/>
    <!-- update this variable on how deep your navigation should be -->
    <xsl:variable name="maxLevel" select="5"/>
    <xsl:variable name="menuSection" select="//PL_MenuSection" />

    <xsl:template match="/">
    <ul id="{$menuSection}">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=$startLevel]"/>
    </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='naviHide']) != '1' and @level &lt;= $maxLevel) ]">

    <xsl:variable name="class" >
    <xsl:choose>
    <xsl:when test="@level = 2" ><xsl:value-of select="$menuSection" />_Title</xsl:when>
    </xsl:choose>
    </xsl:variable>

    <li class="{$class}" >
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    <xsl:if test="count(./node [string(./data [@alias='naviHide']) != '1' and @level &lt;= $maxLevel]) &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>

     

     

  • joe huang 7 posts 26 karma points
    Sep 02, 2011 @ 04:36
    joe huang
    0

    handle multilingual menu items - Xslt

    we have a multi-lingual site with following structure supported by umbraco. 

     

    Content

     USA Site: 

             index page

             item1...

             ... 

     Canadian Site: 

        English

              index page in English...

             item1...

             ...  

        French

             index page in French...

             item1...

             ...  

     

    I know the better way is to put the Canadian Site as a separate site, but our client only wants a single login for admin account.  So we have an xslt navigation file to load the menu for the US site,  another xslt navigation file to load the menu for Canadian site English version, and the third xslt navigation file to load the menu for Canadian site English version.  Now it works well for the US site. But this only works for the index pages on Canadian site. Once we go the sub pages, the menu doesn't show up.

     

    The xslt for French version of Canadian site is below. Please note I hard code id 1795 and 1884 and 1885 for the specific reason noted. I appreciate any suggestions.

  • joe huang 7 posts 26 karma points
    Sep 02, 2011 @ 04:37
    joe huang
    0

     Below is the xslt for french section. We know the problem is that the submenu is never reached,  but don't knwo why,

     

     

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

     

      <xsl:param name="currentPage"/>

      <xsl:param name="level" select="1"/>

     

      <!-- 1795 is the home page for Canadian Site, we start from this node to display the menu item in order to skip the ones for the US site -->

      <xsl:variable name="rootId" select="1795"/>

      <xsl:variable name="stopLevel" select="/macro/maxDepth"/>

      <xsl:variable name="mystartNodeId" select="/macro/startNodeId"/>

      <xsl:variable name="cssClass" select="/macro/NavigationCSSClass"/>

      <xsl:variable name="cssID" select="/macro/NavigationCSSId"/>

      <xsl:variable name="boolImageLink" select="/macro/navImageLink"/>

      <xsl:variable name="IDSelectorPrefix" select="/macro/IDPrefix"/>

      <xsl:variable name="disableNav" select="/macro/disableNav"/>

     

      <xsl:template match="/">

        <xsl:call-template name="menu">

          <xsl:with-param name="level" select="$level"/>

        </xsl:call-template>

      </xsl:template>

     

      <xsl:template name="menu">

        <xsl:param name="level"/>

     

        <ul class="level_{$level}">

          <xsl:if test="string($cssClass)">

            <xsl:attribute name="class">

              <xsl:value-of select="$cssClass"/> level_{$level}

              <xsl:if test="$disableNav = 1"> disabled</xsl:if>

            </xsl:attribute>

          </xsl:if>

          <xsl:if test="$cssID!= ''">

            <xsl:attribute name="id">

              <xsl:value-of select="$cssID"/>

            </xsl:attribute>

          </xsl:if>

          <xsl:if test="count($currentPage/ancestor::root/* [@level=$level and @id = $rootId]/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">

            <xsl:for-each select="$currentPage/ancestor::root/* [@level=$level and @id = $rootId]/* [@isDoc and string(umbracoNaviHide) != '1']">

     

     

              <!-- 1884 is the id for the "fr" node for Canadian Site -->

              <xsl:if test="($currentPage/@id = current()/@id) or ((string($currentPage/@id) = $rootId) and (string(current()/@id) ='1884'))">

                <xsl:for-each select="current()/*[@isDoc and string(umbracoNaviHide) != '1']">

                  <xsl:variable name="currentNode" select="."/>

     

                  <li>

                    <!-- 1885 is the id for the index page for Canadian Site French version-->

                    <xsl:if test="($currentPage/@id = current()/@id)or ((string($currentPage/@id) = $rootId) and (string(current()/@id) = '1885'))or ((string($currentPage/@id) = 1884) and (string(current()/@id) = '1885'))">

                      <xsl:attribute name="class">current-page</xsl:attribute>

                    </xsl:if>

                    <xsl:if test="$currentPage/ancestor::*/@id = current()/@id">

                      <xsl:attribute name="class">current-page-ancestor</xsl:attribute>

                    </xsl:if>

                    <xsl:call-template name="buildLink">

                      <xsl:with-param name="node" select="current()"/>

                    </xsl:call-template>

     

                    <xsl:if test="count(current()/* [@isDoc and (string(umbracoNaviHide) != '1')]) &gt; '0'">

                      <xsl:call-template name="submenu">

                        <xsl:with-param name="level" select="$level+1"/>

                      </xsl:call-template>

                    </xsl:if>

     

                  </li>

                </xsl:for-each>

              </xsl:if>

            </xsl:for-each>

          </xsl:if>

        </ul>

      </xsl:template>

     

      <xsl:template name="submenu">

        <xsl:param name="level"/>

     

        <xsl:variable name="currentProcessedNode" select="."/>

        <xsl:if test="string($currentProcessedNode/umbracoHideChildren) != '1'">

          <ul class="level_{@level}">

            <xsl:for-each select="current()/* [@isDoc and string(umbracoNaviHide) != '1']">

              <xsl:variable name="currentNode" select="."/>

              <li>

                <xsl:if test="$currentPage/@id = current()/@id">

                  <xsl:attribute name="class">current-page</xsl:attribute>

                </xsl:if>

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

                  <xsl:value-of select="@nodeName"/>

                </a> -->

                <xsl:call-template name="buildLink">

                  <xsl:with-param name="node" select="$currentNode"/>

                </xsl:call-template>

              </li>

            </xsl:for-each>

          </ul>

        </xsl:if>

      </xsl:template>

     

      <xsl:template name="buildLink">

        <xsl:param name="node"/>

     

        <xsl:choose>

          <!-- Build link to external page -->

          <xsl:when test="string($node/externalURL) != ''">

            <xsl:call-template name="buildExternalLink">

              <xsl:with-param name="node" select="$node"/>

            </xsl:call-template>

          </xsl:when>

     

          <!-- Build link for redirecting to a custom supplied url -->

          <xsl:when test="string($node/umbracoRedirect) != ''">

            <xsl:call-template name="buildRedirectLink">

              <xsl:with-param name="node" select="$node"/>

            </xsl:call-template>

          </xsl:when>

     

          <!-- Default link builder -->

          <xsl:otherwise>

            <xsl:call-template name="buildNormalLink">

              <xsl:with-param name="node" select="$node"/>

            </xsl:call-template>

          </xsl:otherwise>

        </xsl:choose>

      </xsl:template>

     

      <xsl:template name="buildExternalLink">

        <xsl:param name="node"/>

     

        <!--

        <xsl:call-template name ="outputNode">

          <xsl:with-param name="currentNode" select="$node"/>

        </xsl:call-template>

        -->

     

        <a>

          <!-- Set the href attribute -->

          <xsl:attribute name="href">

            <xsl:value-of select="$node/externalURL"/>

          </xsl:attribute>

          <!-- Set the target attribute if available from the properties -->

          <xsl:if test="string($node/externalTarget) != ''">

            <xsl:attribute name="target">

              <xsl:value-of select="$node/externalTarget"/>

            </xsl:attribute>

          </xsl:if>

          <!-- Set the title attribute if available from the properties -->

          <xsl:if test="string($node/navTooltip) != ''">

            <xsl:attribute name="title">

              <xsl:value-of select="string($node/navTooltip)"/>

            </xsl:attribute>

          </xsl:if>

          <xsl:if test="string($node/openInNewWindow) = '1'">

            <xsl:attribute name="target">_blank</xsl:attribute>

          </xsl:if>

          <!-- Set actual text for the link, either available from the properties or just plain umbraco link-->

          <xsl:choose>

            <xsl:when test="string($node/navText) != ''">

              <xsl:value-of select="string($node/navText)"/>

            </xsl:when>

            <xsl:otherwise>

              <xsl:value-of select="$node/@nodeName"/>

            </xsl:otherwise>

          </xsl:choose>

        </a>

     

      </xsl:template>

     

      <xsl:template name="buildRedirectLink">

        <xsl:param name="node"/>

     

        <!--

        <xsl:call-template name ="outputNode">

          <xsl:with-param name="currentNode" select="$node"/>

        </xsl:call-template>

        -->

     

        <a>

          <!-- Set the href attribute based on the redirect supplied -->

          <xsl:attribute name="href">

            <xsl:value-of select="netaddicts-be:FixLink(string($node/umbracoRedirect))"/>

          </xsl:attribute>

          <!-- Set the title attribute if available from the properties -->

          <xsl:if test="string($node/navTooltip) != ''">

            <xsl:attribute name="title">

              <xsl:value-of select="string($node/navTooltip)"/>

            </xsl:attribute>

          </xsl:if>

     

          <xsl:if test="string($node/openInNewWindow) = '1'">

            <xsl:attribute name="target">_blank</xsl:attribute>

          </xsl:if>

     

          <!-- Set actual text for the link, either available from the properties or just plain umbraco link-->

          <xsl:choose>

            <xsl:when test="string($node/navText) != ''">

              <xsl:value-of select="string($node/navText)"/>

            </xsl:when>

            <xsl:otherwise>

              <xsl:value-of select="$node/@nodeName"/>

            </xsl:otherwise>

          </xsl:choose>

        </a>

     

      </xsl:template>

     

      <xsl:template name="buildNormalLink">

        <xsl:param name="node"/>

     

        <!--

        <xsl:call-template name ="outputNode">

          <xsl:with-param name="currentNode" select="$node"/>

        </xsl:call-template>

        -->

     

        <a>

          <!-- Set the href attribute, either the alias if available, else use NiceUrl() -->

          <xsl:attribute name="href">

            <xsl:choose>

              <xsl:when test="string($node/umbracoUrlAlias) != ''">

                <xsl:value-of select="netaddicts-be:FixLink(string($node/umbracoUrlAlias))"/>

              </xsl:when>

              <xsl:otherwise>

                <xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>

              </xsl:otherwise>

            </xsl:choose>

          </xsl:attribute>

          <!-- Set the title attribute if available from the properties -->

          <xsl:if test="string($node/navTooltip) != ''">

            <xsl:attribute name="title">

              <xsl:value-of select="string($node/navTooltip)"/>

            </xsl:attribute>

          </xsl:if>

          <!-- Set actual text for the link, either available from the properties or just plain umbraco link-->

          <xsl:choose>

            <xsl:when test="string($node/navText) != ''">

              <xsl:value-of select="string($node/navText)"/>

            </xsl:when>

            <xsl:otherwise>

              <xsl:value-of select="$node/@nodeName"/>

            </xsl:otherwise>

          </xsl:choose>

        </a>

     

      </xsl:template>

     

      <!-- For debugging purposes, writes out all relevant node properties -->

      <xsl:template name="outputNode">

        <xsl:param name="currentNode"/>

        <ul>

          <li>

            @id=<xsl:value-of select="$currentNode/@id"/>

          </li>

          <li>

            @nodeName=<xsl:value-of select="$currentNode/@nodeName"/>

          </li>

          <li>

            @umbracoNaviHide=<xsl:value-of select="$currentNode/umbracoNaviHide"/>

          </li>

          <li>

            @umbracoHideChildren=<xsl:value-of select="$currentNode/umbracoHideChildren"/>

          </li>

          <li>

            @navText=<xsl:value-of select="$currentNode/navText"/>

          </li>

          <li>

            @navTooltip=<xsl:value-of select="$currentNode/navTooltip"/>

          </li>

          <li>

            @externalURL=<xsl:value-of select="$currentNode/externalURL"/>

          </li>

          <li>

            @externalTarget=<xsl:value-of select="$currentNode/externalTarget"/>

          </li>

          <li>

            @umbracoRedirect=<xsl:value-of select="$currentNode/umbracoRedirect"/>

          </li>

          <li>

            @umbracoUrlAlias=<xsl:value-of select="$currentNode/umbracoUrlAlias"/>

          </li>

        </ul>

      </xsl:template>

     

     

      

  • joe huang 7 posts 26 karma points
    Sep 02, 2011 @ 04:53
    joe huang
    0

    A little more inof:

    We tired the US content to domain.com and the Canadian content to domain.ca

Please Sign in or register to post replies

Write your reply to:

Draft