Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Aug 19, 2010 @ 18:20
    trfletch
    0

    Nested superfish menu with curved borders

    Hi All,

    I have an Umbraco 4.5 site (running old XSLT schema) and I have a nested horizontal flyout menu that uses superfish jquery plugin (http://www.jankoatwarpspeed.com/examples/vimeo_navigation/) with supersubs (the sub menu width adjusts to the size of the largest item). This all works fine and I have used it on many sites but I have a site where I need the borders of the sub-menu to be curved similar to the menu on the following link when you hover over "Help" (http://www.jankoatwarpspeed.com/examples/vimeo_navigation/).

    Looking at the code on that site it seems like they have put an image either side of the first "li" of the sub menu to create the curves at the top and the last "li" of the submenu contains images as well to create the curves at the bottom. That is all well and good with a static menu but my menu is created dynamically using XSLT based on the sitemap template. Can anyone tell me how I can modify my code so that it knows what the first "li" of the sub menu is and puts an image either side and also adds another "li" at the end of each submenu that I can put images in? 

    My current XSLT is as follows:

    <xsl:param name="currentPage"/>
     

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
    <xsl:template match="/">


    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(1053)/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </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="sf-menu"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>

    <xsl:otherwise>
     <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    </li>
    </xsl:otherwise>
    </xsl:choose>

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

    Thanks in advance for any help :-)

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 19, 2010 @ 21:39
    bob baty-barr
    3

    if you check for position() in your for-each loops and apply a class to the li, that should handle what you need...

    so...

    <li>

    <xsl:if test="position() = 1">

    <xsl:attribute name="class">first</xsl:attribute>

    </xsl:if>

    </li>

    same thing for position()=last()

    hope that points you in teh right direction.

  • trfletch 598 posts 604 karma points
    Aug 20, 2010 @ 11:50
    trfletch
    0

    Hi Bob,

    Thanks for the response, I thought I might have to use something like that but wouldn't that apply it to the first menu item as well as the first submenu item? How do I stop it applying it to the first menu item and only apply it to the first sub menu items?

  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 20, 2010 @ 15:33
    Ferdy Hoefakker
    1
    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:param name="isSubItem"/>
    <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="sf-menu">

    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">

    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>

    <xsl:otherwise>
    <li>
    <xsl:if test="position() = 1" and $isSubItem = true>
    <xsl:attribute name="class">first</xsl:attribute>
    </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    <xsl:if test="position() = last() and $isSubItem = true">
    <li class="last">&nbsp;</li>
    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>


    <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="isSubItem" select="true"/>
    </xsl:call-template>
    </xsl:if>

    </xsl:for-each>

    </ul>

    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    I -think- that should be it, but I am no expert (yet anyway :P). Adding a second parameter that only gets a value if the drawNodes template is called from the drawNodes function should do the trick. Not entirely certain this is allowed though. But it's worth a shot :P

    -Ferdy

  • trfletch 598 posts 604 karma points
    Aug 20, 2010 @ 17:24
    trfletch
    0

    Hi Ferdy,

    Thanks for the response, I have used the code you supplied and merged it into what I already have but I am getting an error when trying to save, is there something that I have missed? This is the code I have and below that is the error:

     

     

    <xsl:param name="currentPage"/>
     
     <xsl:include href="e-commerce-menu.xslt" />
     
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
     
    <xsl:template match="/">
    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:param name="isSubItem"/>
    <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="sf-menu">

    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
     
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>
    <xsl:when test="@nodeTypeAlias = 'Commercemenu'">
      <xsl:call-template name="ecommercemenu">
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     
    <li>

    <xsl:if test="position() = 1 and $isSubItem = true">
        <xsl:attribute name="class">first</xsl:attribute> 
    </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    </li>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">  
    <xsl:call-template name="drawNodes">   
    <xsl:with-param name="isSubItem" select="true"/>   
    </xsl:call-template> 
    </xsl:if>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

     

     

    Error occured

    System.Xml.Xsl.XslTransformException: Expression must evaluate to a node-set.
    at System.Xml.Xsl.Runtime.XsltConvert.EnsureNodeSet(IList`1 listItems)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent, IList`1 isSubItem)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent, IList`1 isSubItem)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

  • trfletch 598 posts 604 karma points
    Aug 20, 2010 @ 18:22
    trfletch
    1

    Ok I have been playing with the code and it seems I was wrong to doubt Bob in the first place, especially without trying out what he said because it seems that doing what he said does in fact only add it the the first "li" item of the submenu and not to the top level menu therefore I am now using the following code which adds an image either side of the first link in the submenu, just need to setup my styles now to make it look nice (that should be fun!). Thanks for all the help everyone. This is my code, let me know if there are any improvements I can make to it:

     

    <xsl:param name="currentPage"/>
     
     <xsl:include href="e-commerce-menu.xslt" />
     
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
     
    <xsl:template match="/">
    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </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="sf-menu"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
     
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>
    <xsl:when test="@nodeTypeAlias = 'Commercemenu'">
      <xsl:call-template name="ecommercemenu">
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <li>
    <xsl:if test="position() = 1">
        <xsl:attribute name="class">first</xsl:attribute>   
     <img src="/images/corner_inset_left.png" />
     <a href="{umbraco.library:NiceUrl(@id)}">
     <xsl:value-of select="@nodeName"/></a>
     <img src="/images/corner_inset_right.png" />

    </xsl:if>
    <xsl:if test="position() != 1">
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/></a>
    </xsl:if>
    </li>
    </xsl:otherwise>
    </xsl:choose>

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

    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 20, 2010 @ 18:49
    bob baty-barr
    0

    nice work! glad you sorted it all out!

  • trfletch 598 posts 604 karma points
    Aug 20, 2010 @ 19:28
    trfletch
    0

    Seems I spoke too soon, I have managed to get the curve on the first item ok but the last one is turning out to be a problem is seems by using the same method and trying to add images either side of the last "li" item it is in fact adding images either side of the last item on the first level menu as well as the submenu (if that makes sense!). Anyone know why this is and how I can stop it? Also I have an issue with it repeating the History link because that is both the first link and the last link in the submenu. Ideally I would like to be able to add an additional "li" item at the end of each sub menu that I could put the bottom curves in if that is possible. This is my code and below it is my output:

     

    <xsl:param name="currentPage"/>
     
     <xsl:include href="e-commerce-menu.xslt" />
     
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
     
    <xsl:template match="/">
    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </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="sf-menu"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
     
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>
    <xsl:when test="@nodeTypeAlias = 'Commercemenu'">
      <xsl:call-template name="ecommercemenu">
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <li>
    <xsl:if test="position() = 1">
        <xsl:attribute name="class">first</xsl:attribute>   
     <img class="corner_inset_left" src="/images/corner_inset_left.png" />
     <a href="{umbraco.library:NiceUrl(@id)}">
     <xsl:value-of select="@nodeName"/></a>
     <img class="corner_inset_right" src="/images/corner_inset_right.png" />
    </xsl:if>
    <xsl:if test="position() != 1 and position() != last()">
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/></a>
    </xsl:if>
    <xsl:if test="position() = last()">
      <img class="corner_left" alt="" src="/images/corner_left.png"/>
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/></a>
      <img class="corner_left" alt="" src="/images/corner_right.png"/>
    </xsl:if>

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

     

    and this is the output source for the menu:

    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li></ul>
    <ul class="sf-menu">
    <li><a href="/link1.aspx">Link 1</a></li>
    <li><a href="/link2.aspx">Link 2</a></li>
    <li><a href="/friends.aspx">Friends</a></li>
    <li><a href="/about-us.aspx">About us</a></li>
    <ul class="sf-menu">
    <li class="first">
    <img class="corner_inset_left" src="/images/corner_inset_left.png" />
    <a href="/about-us/history.aspx">History</a>
    <img class="corner_inset_right" src="/images/corner_inset_right.png" />
    <img class="corner_left" alt="" src="/images/corner_left.png" />
    <a href="/about-us/history.aspx">History</a>
    <img class="corner_left" alt="" src="/images/corner_right.png" />
    </li>
    </ul>
    <li><a href="/help.aspx">Help</a></li>
    <ul class="sf-menu">
    <li class="first">
    <img class="corner_inset_left" src="/images/corner_inset_left.png" />
    <a href="/help/refunds-and-returns.aspx">Refunds and returns</a>
    <img class="corner_inset_right" src="/images/corner_inset_right.png" />
    </li>
    <li><a href="/help/privacy-policy.aspx">Privacy policy</a></li>
    <li><a href="/help/delivery-information.aspx">Delivery information</a></li>
    <li>
    <img class="corner_left" alt="" src="/images/corner_left.png" />
    <a href="/help/testdd.aspx">testdd</a><img class="corner_left" alt="" src="/images/corner_right.png" /></li>
    </ul>
    <li>
    <img class="corner_left" alt="" src="/images/corner_left.png" />
    <a href="/contact-us.aspx">Contact us</a>
    <img class="corner_left" alt="" src="/images/corner_right.png" />
    </li>
    </ul>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 20, 2010 @ 19:34
    bob baty-barr
    0

    let's take a look at your xslt...

    basically, you are calling a template to render ALL of your menu items...

    so, if you don't want the images on the first level of the menu... you could add an additional contidion to your xsl:if test statement...

    @level != '1' -- this would say, when the level is not equal to 1 then let's put the images on the first and the last...

    <xsl:if test="position() = 1 and @level != 1">
  • trfletch 598 posts 604 karma points
    Aug 23, 2010 @ 13:24
    trfletch
    0

    Hi Bob,

    Thanks again for your help, that has pointed me in the right direction and I now have it working almost how I want, the only issue I have left is if the submenu only has 1 item, if that is the case then I want it to add images to either side of the "li" and also give it a class of "lastSubItem", I did try putting a when statement that said if it was position 1 and also position last then do the following but that that did not seem to work (not sure why), is there another bit of code I can put in my "when" statement to do something similar (basically needs to say if this is the only item)? This is what I currently have, the part I am refering to is at the end in the listLinks template:

    <xsl:param name="currentPage"/>
     
     <xsl:include href="e-commerce-menu.xslt" />
     
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="3"/>
     
    <xsl:template match="/">
    <ul class="sf-menu">
    <li><a href="/" class="firstlink">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </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="sf-menu">
    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">


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

    <xsl:when test="@nodeTypeAlias = 'Commercemenu'">
      <xsl:call-template name="ecommercemenu">
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <li>
      <xsl:call-template name="listLinks">   
      </xsl:call-template>
     
     <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">  
      <xsl:call-template name="drawNodes">   
      <xsl:with-param name="parent" select="."/>   
      </xsl:call-template> 
     </xsl:if>
    </li>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>

    <xsl:template name="listLinks">
    <xsl:choose>
     
    <xsl:when test="position() = 1 and @level != 2">
           
     
     <xsl:attribute name="class">first</xsl:attribute> 
     <img class="corner_inset_left" src="/images/corner_inset_left.png" />
     <a href="{umbraco.library:NiceUrl(@id)}">
     <xsl:value-of select="@nodeName"/></a>
     <img class="corner_inset_right" src="/images/corner_inset_right.png" />
     
    </xsl:when>
    <xsl:when test="position() = last() and @level != 2">
      <xsl:attribute name="class">lastSubItem</xsl:attribute>
      <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a> 
    </xsl:when>
    <xsl:otherwise>
     
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/></a>
     
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 23, 2010 @ 22:46
    bob baty-barr
    0

     

    you can add one more layer of logic and set a specific class if the count of the nodes in the for each = 1 ....

    so basically a chose statment...

    <xsl:choose>
    <xsl:when test="condition1"> <!-- this would be if the count only equals one -->
    set the class here
    </xsl:when>

    <xsl:when test="condition2">
    set the other class
    </xsl:when>

    <xsl:otherwise>
    set the default class
    </xsl:otherwise>
    </xsl:choose>

    Hope that helps...

  • trfletch 598 posts 604 karma points
    Aug 24, 2010 @ 12:03
    trfletch
    0

    Hi Bob,

    Thanks again for the response, I thought that would be the case but the problem I have is that I'm not sure what the code is that I need to check if it is the only one, what do I put in the "when" statement to check if it is the only li item in the submenu?

  • trfletch 598 posts 604 karma points
    Aug 26, 2010 @ 18:35
    trfletch
    0

    Sorry to go on about this one but can anyone help me with the code that I need to make this work, I assume I need to add something another when statement like the last one shown in the code below but I don't know what to put where the XXX's are:

    <xsl:choose>
     
    <xsl:when test="position() = 1 and @level != 2">
           
     
     
    <xsl:attribute name="class">first</xsl:attribute>
     
    <img class="corner_inset_left" src="/images/corner_inset_left.png" />
     
    <a href="{umbraco.library:NiceUrl(@id)}">
     
    <xsl:value-of select="@nodeName"/></a>
     
    <img class="corner_inset_right" src="/images/corner_inset_right.png" />
     
    </xsl:when>
    <xsl:when test="position() = last() and @level != 2">
     
    <xsl:attribute name="class">lastSubItem</xsl:attribute>
     
    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
    </xsl:when>





    <xsl:when test="count(XXX) = 1 and @level != 2">
     
    <xsl:attribute name="class">lastSubItem</xsl:attribute>
     
    <img class="corner_inset_left" src="/images/corner_inset_left.png" />
    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
    <img class="corner_inset_right" src="/images/corner_inset_right.png" />

    </xsl:when>
    <xsl:otherwise>
     
     
    <a href="{umbraco.library:NiceUrl(@id)}">
     
    <xsl:value-of select="@nodeName"/></a>
     
    </xsl:otherwise>
    </xsl:choose>

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 26, 2010 @ 20:40
    bob baty-barr
    0

    the count statement would be the same as your for-each statement that got you into the template...

    count(./node [string(./data [@alias='umbracoNaviHide']) != '1') = 1
  • trfletch 598 posts 604 karma points
    Aug 27, 2010 @ 18:21
    trfletch
    0

    Hi Bob,

    Thanks for the response and thanks for being so patient with me, I tried what you said:

    <xsl:when test="count(./node) = 1">
     ****do something
    </xsl:when>


    but that applies it to the top level node that has only one item rather than applying it to the submenu item itself, for example if I have the following structure then it applies whatever I put in the when statement to the "Test B" menu item as opposed to the "Test B sub 1" item which from looking at the code is understandable:

    Test A
    Test B
         - Test B sub 1
    Test C
         - Test C sub 1
         - Test C sub 2
         - Test C sub 3

    I thought I would be clever and try the following:

    <xsl:when test="count(.) = 1">
     ****do something
    </xsl:when>

    but for some reason unknown to me it applied it to the "Test C sub 2" item! Any ideas?

  • trfletch 598 posts 604 karma points
    Sep 03, 2010 @ 17:59
    trfletch
    0

    Sorry to go on but just wondered if anyone had any thoughts on this? It sounds quite simple what I want to do but seems to be turning out to be more complicated than I first thought.

  • trfletch 598 posts 604 karma points
    Sep 20, 2010 @ 16:11
    trfletch
    0

    Just in case anyone was interested in this I did manage to resolve it finally with the following code, I put in a when statement to check if the item was position = first and also position = last and modified the other when statement to check if it was position = first and position = not last. I did try something similar originally but it didn't seem to work, must of been some dodgy coding! Thank to everyone who helped with this issue. This the XSLT I am now using:

    <xsl:template name="listLinks">

    <xsl:choose>
     
    <xsl:when test="position() = 1 and position() != last() and @level != 2">
     <img class="corner_inset_left" src="/images/corner_inset_left.png" />
     <a href="{umbraco.library:NiceUrl(@id)}">
     <xsl:value-of select="@nodeName"/></a>
     <img class="corner_inset_right" src="/images/corner_inset_right.png" />
    </xsl:when>
    <xsl:when test="position() = 1 and position() = last() and @level != 2">
     <xsl:attribute name="class">lastSubItem</xsl:attribute>
     <img class="corner_inset_left" src="/images/corner_inset_left.png" />
     <a href="{umbraco.library:NiceUrl(@id)}">
     <xsl:value-of select="@nodeName"/></a>
     <img class="corner_inset_right" src="/images/corner_inset_right.png" />
    </xsl:when>
    <xsl:when test="position() = last() and @level != 2">
      <xsl:attribute name="class">lastSubItem</xsl:attribute>
      <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a> 
    </xsl:when>
    <xsl:otherwise>
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/></a>
     </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
Please Sign in or register to post replies

Write your reply to:

Draft