Copied to clipboard

Flag this post as spam?

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


  • David Conlisk 432 posts 1008 karma points
    Aug 20, 2010 @ 12:43
    David Conlisk
    0

    XsltSearch returns children of node that has umbracoNaviHide set to one

    Hi all,

    I wonder if I'm doing something wrong here, but I'm using an un-modified version of XSLT (version 2.8.1) at the moment. In my site I have a folder which contains sidebar items. The folder has umbracoNaviHide set to 1. The sidebar items do not have this property at all - they do not exist as standalone pages on the site. There are hundreds of these items, with many different documenttypes.

    I considered changing the possiblenodes variable so that any child (grandchild, etc) of this node would be excluded from the resultset, but I haven't been successful in this. I tried this kind of thing, but no joy:

    <xsl:variable name="possibleNodes" select="$items/descendant-or-self::*[
                                 @isDoc
                                 and string(umbracoNaviHide) != '1'
                                 and count(attribute::id)=1
                                 and ancestor-or-self::RHSItemsFolder/local-name = ''
                                 and (umbraco.library:IsProtected(@id, @path) = false()
                                  or umbraco.library:HasAccess(@id, @path) = true())
                               ]"/>

    Any ideas?

    Thanks!

    David

  • Daniel Bardi 927 posts 2562 karma points
    Aug 20, 2010 @ 12:44
    Daniel Bardi
    1

    umbracoNaviHide is only used to hide in navigation.  If you don't want it to show up .. simply unpublish or modify the XSLT to exclude nodes with the value set.

  • David Conlisk 432 posts 1008 karma points
    Aug 20, 2010 @ 12:49
    David Conlisk
    0

    Hi Daniel,

    Thanks for your reply but I can't unpublish these sidebar items as they are used across the site - they just do not exist as standalone pages (and so I can't have them appear as links on the search results page). Also, the sidebar items do not have the umbracoNaviHide property - but their parent folder does. I would have thought that if the folder had it set then the child nodes would not be included, but that doesn't seem to be the case.

    David

  • Daniel Bardi 927 posts 2562 karma points
    Aug 20, 2010 @ 13:10
    Daniel Bardi
    1

    You could also skip specific sidebar node types.

    I've done it before with a simple addition to XSLTSearch when it displays the result links

    Find in XSLTsearch.xslt for <xsl:for-each select="$matchedNodes">

    Replace with <xsl:for-each select="$matchedNodes [@nodeTypeAlias != 'SidebarNode']">

  • David Conlisk 432 posts 1008 karma points
    Aug 20, 2010 @ 13:13
    David Conlisk
    0

    Yeah but the problem I have just now is that there are loads of these document types - I'd rather somehow exclude all items below that specific folder from the search results.

  • Daniel Bardi 927 posts 2562 karma points
    Aug 20, 2010 @ 13:19
    Daniel Bardi
    1

    Then try this:

    <xsl:for-each select="$matchedNodes [./parent::node/@id != '1234']">

    where 1234 is your parent node id containing all sidebar nodes

  • David Conlisk 432 posts 1008 karma points
    Aug 20, 2010 @ 13:50
    David Conlisk
    1

    Thanks very much for your help, Daniel - it definitely put me on the right track. I replaced this:

    <xsl:variable name="matchedNodes" select="$possibleNodes[contains($matchedNodesIdList, concat(';', concat(@id, ';')))]" />

    with this:

    <xsl:variable name="RHSItemsFolderId" select="$currentPage/ancestor-or-self::homepage/RHSItemsFolder/@id"/>
    <xsl:variable name="prematchedNodes" select="$possibleNodes[contains($matchedNodesIdList, concat(';', concat(@id, ';')))]" />
    <xsl:variable name="matchedNodes" select="$prematchedNodes[parent::*/@id != $RHSItemsFolderId and parent::*/parent::*/@id != $RHSItemsFolderId]" />

     

    because there are two levels of nodes below the folder in question, and it's a multilingual site so I can't hardcode the folder id. I need to check both parent and grandparent explicitly as using ancestor-or-self would include the result - I need items whose parent and grandparent are BOTH not the folder in question.

    Anyway, it works now. Thanks again!

    David

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 20, 2010 @ 14:48
    Chriztian Steinmeier
    2

    Hi David,

    Instead of ancestor-or-self:: you could use ancestor:: to not include the result itself. Also, the "XSLT-idiomatic" way of writing something != something-else is to flip it and use the not() function:

    <xsl:variable name="matchedNodes" select="$prematchedNodes[not(ancestor::*[@id = $RHSItemsFolderId])]" />

    /Chriztian

  • Daniel Bardi 927 posts 2562 karma points
    Aug 20, 2010 @ 20:50
    Daniel Bardi
    0

    David,

    Glad to assist.  Great news that it's working for you.

    Chriztian,

    Totally spaced the not() method.  Thanks!

  • David Conlisk 432 posts 1008 karma points
    Aug 23, 2010 @ 09:56
    David Conlisk
    0

    Nice one Chriztian, using the not method is a lot neater.

Please Sign in or register to post replies

Write your reply to:

Draft