Dropdown menu - something wacky Options
andrew
Posted: Tuesday, July 08, 2008 3:30:26 PM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
Hi

I have modified the website wizard pulldoem menu to work with adxMenu, as well as add a menu item to my home, hide events, and news items. When I save the xslt, I get an error related to the <ul> tag, but if I save without error checking, the menu works.......until you have a umbraconavhide in the middle somewhere, then it goes all haywire. My XSLt skill is limited to say the least, so I would appreciate it if someone was able to look at the attached and identify the gremlin/s

Thanks
Andrew

Code:

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

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

<xsl:template match="/">

    <xsl:call-template name="printListe">
        <xsl:with-param name="node" select="$currentPage/ancestor-or-self::node [@level = 1]"/>    
        <xsl:with-param name="id" select="string('menuList')"/>    
    </xsl:call-template>
</xsl:template>

<xsl:template name="printListe">
    <xsl:param name="node"/>
    <xsl:param name="id"/>
<ul>
    <xsl:if test="$id != ''">
        <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
        <xsl:attribute name="class"><xsl:value-of select="string('adxm menu')"/></xsl:attribute>
        <li><a href="/default.aspx">Home</a></li>
    </xsl:if>
    <xsl:if test="$id = ''">
        <xsl:attribute name="id">submenu<xsl:value-of select="current()/@id"/></xsl:attribute>    
        <xsl:attribute name="class">sublist</xsl:attribute>
    </xsl:if>
    <xsl:for-each select="$node/node [string(./data [@alias='umbracoNaviHide']) != 1]">
        <xsl:if test="$node/node [@nodeTypeAlias != 'News Item']">
            <xsl:if test="$node/node [@nodeTypeAlias != 'event']">
                <li>
                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                        <xsl:attribute name="class">submenu</xsl:attribute>
                    </xsl:if>
                    <div>
                        <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
                    </div>

                    <xsl:if test="count(./node) &gt; 0">
                        <xsl:call-template name="printListe">
                            <xsl:with-param name="node" select="."/>
                        </xsl:call-template>
                    </xsl:if>
                </li>
            </xsl:if>
        </xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>

andrew
Posted: Monday, July 14, 2008 10:45:54 PM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
I have managed to sort out my menu, but am having problem with using an "or" statement in a XSLT For-each. Could someone please tell me what the correct syntaxc for the following should be:

<xsl:for-each select="$parent/node [@nodeTypeAlias != 'News Item' or @nodeTypeAlias != 'Event' or @nodeTypeAlias != 'umbracoBlogPost' or @nodeTypeAlias != 'umbracoBlogDateFolder' or @nodeTypeAlias != 'umbracoBlogComment' or string(./data [@alias='umbracoNaviHide']) != 1]">
drobar
Posted: Tuesday, July 15, 2008 3:53:51 AM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,410
Location: KY, USA
Looks pretty good to me... I don't think you need the ./data in the string(), and you want to test your string() against a string rather than a number. The big problem, as I see it is that you really want AND, not OR.


This will work:
Code:

<xsl:for-each select="$currentPage/node [
          @nodeTypeAlias = 'MyDocTypeAlias'
          and string(data [@alias='umbracoNaviHide']) != '1'
]">


So, similarly, this should work (didn't try it)
Code:

<xsl:for-each select="$parent/node [
          @nodeTypeAlias != 'News Item'
          and @nodeTypeAlias != 'Event'
          and @nodeTypeAlias != 'umbracoBlogPost'
          and @nodeTypeAlias != 'umbracoBlogDateFolder'
          and @nodeTypeAlias != 'umbracoBlogComment'
          and string(data [@alias='umbracoNaviHide']) != '1'
]">


Hope this helps.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
andrew
Posted: Tuesday, July 15, 2008 9:46:06 AM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
Thanks doug - the "and" worked, although it makes more sense to me to use "or", but I suppose that is my xslt ignorance coming through :)
Dirk
Posted: Tuesday, July 15, 2008 10:00:48 AM

Rank: Fanatic

Joined: 9/27/2007
Posts: 463
Location: Belgium
I'm quite sure using 'or' instead of 'and' will render completely different results! I wouldn't ignore it, it will be much more important than you might think.

Code:
<xsl:for-each select="$parent/node [
          @nodeTypeAlias != 'News Item'
          and @nodeTypeAlias != 'Event'
          and @nodeTypeAlias != 'umbracoBlogPost'
          and @nodeTypeAlias != 'umbracoBlogDateFolder'
          and @nodeTypeAlias != 'umbracoBlogComment'
          and string(data [@alias='umbracoNaviHide']) != '1'
]>


rewritten to use 'or' instead of 'and'

Code:
<xsl:for-each select="$parent/node [
          not (@nodeTypeAlias = 'News Item'
          or @nodeTypeAlias = 'Event'
          or @nodeTypeAlias = 'umbracoBlogPost'
          or @nodeTypeAlias = 'umbracoBlogDateFolder'
          or @nodeTypeAlias = 'umbracoBlogComment'
          or string(data [@alias='umbracoNaviHide']) != '1'
]>


Regards,
/Dirk


level 1 certified - umbraco blog at netaddicts.be
andrew
Posted: Tuesday, July 22, 2008 3:50:12 PM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
hi all again - I am ressurecting this topic because i have one more quirk I need to sort out. My menu is working exactely how I need it to, except the order in which the items is displayed is in the order they were created, and not the order i have ended up with through using the sort option. What do I need to modify in order to get the correct sort order. Here is my final XSLT:

Code:

<?xml version="1.0" encoding="utf-8"?>
<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="html"/>

        <xsl:param name="currentPage"/>
       
        <xsl:template match="/">
                <div id="topmenu">
                        <xsl:call-template name="drawNodes">
                                <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
                                <xsl:with-param name="id" select="string('menuList')"/>    
                        </xsl:call-template>
                </div>
        </xsl:template>

        <xsl:template name="drawNodes">
                <xsl:param name="parent"/>
                <xsl:param name="id"/>
                <ul>
                    <xsl:if test="$id != ''">
                        <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
                        <xsl:attribute name="class"><xsl:value-of select="string('adxm menu')"/></xsl:attribute>
                        <li><a href="/default.aspx">Home</a></li>
                    </xsl:if>
                    <xsl:if test="$id = ''">
                        <xsl:attribute name="id">submenu<xsl:value-of select="current()/@id"/></xsl:attribute>    
                        <xsl:attribute name="class">sublist</xsl:attribute>
                    </xsl:if>
                         <!--     <xsl:for-each select="$node/node [string(./data [@alias='umbracoNaviHide']) != 1 or @nodeTypeAlias != 'News Item' or @nodeTypeAlias != 'Event' or @nodeTypeAlias != 'umbracoBlogPost' or @nodeTypeAlias != 'umbracoBlogDateFolder' or @nodeTypeAlias != 'umbracoBlogComment']"> -->
                     <xsl:for-each select="$parent/node [
                        @nodeTypeAlias != 'News Item'
                        and @nodeTypeAlias != 'Event'
                        and @nodeTypeAlias != 'umbracoBlogPost'
                        and @nodeTypeAlias != 'umbracoBlogDateFolder'
                        and @nodeTypeAlias != 'umbracoBlogComment'
                        and string(data [@alias='umbracoNaviHide']) != '1'
                    ]">
                        <li>
                            <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
                            <xsl:call-template name="drawNodes">
                                <xsl:with-param name="parent" select="."/>
                            </xsl:call-template>
                        </li>
                    </xsl:for-each>
                </ul>
        </xsl:template>
</xsl:stylesheet>


Thanks
Andrew
drobar
Posted: Tuesday, July 22, 2008 4:02:07 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,410
Location: KY, USA
Hi, Andrew,

Some people have reported that the sort order in the umbraco UI is not always reflected in the order of items returned by xslt. Usually, publishing all the nodes (check the 'publish children' box) and/or using the 'republish entire site' menu will resolve the issue.

In any event, the solution in those cases where you're seeing peculiar sorting (or just to avoid it's appearance) is to specifically sort the nodes.

Add the following as the first line inside your for-each loop to sort the nodes...
Code:
<xsl:sort select="@sortOrder" data-type="number" order="descending" />


The result would be...
Code:
<xsl:for-each select="$parent/node [
                        @nodeTypeAlias != 'News Item'
                        and @nodeTypeAlias != 'Event'
                        and @nodeTypeAlias != 'umbracoBlogPost'
                        and @nodeTypeAlias != 'umbracoBlogDateFolder'
                        and @nodeTypeAlias != 'umbracoBlogComment'
                        and string(data [@alias='umbracoNaviHide']) != '1'
                    ]">
                    <xsl:sort select="@sortOrder" data-type="number" order="descending" />


That should do it.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
andrew
Posted: Tuesday, July 22, 2008 4:17:55 PM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
Doug - Thanks a million

I have added the neccessary code, although..as you said, "republish entire site" sorted it out.

I love this forum because the umbraco boffins are always so willing to happily impart wisdom!

Andrew
andrew
Posted: Tuesday, July 22, 2008 5:01:46 PM

Rank: Enthusiast

Joined: 2/28/2008
Posts: 25
i found: <xsl:sort select="@sortOrder" data-type="number" order="ascending" /> instead of order="descending" replicates the sort order correctly
asdf-1
Posted: Friday, July 25, 2008 6:18:13 PM
Rank: Newbie

Joined: 6/18/2008
Posts: 9
Location: Chile
Quote:

i found: <xsl:sort select="@sortOrder" data-type="number" order="ascending" /> instead of order="descending" replicates the sort order correctly


thanks!!!
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.