Copied to clipboard

Flag this post as spam?

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


  • BarneyHall 141 posts 210 karma points
    Jan 19, 2010 @ 19:40
    BarneyHall
    0

    Trying to exclude child nodes in menu XSLT

    Hi, pulling my hair out here...

    I'm using the following if statement to check current() doesn't have a nodeTypeAlias of either jobPost or jobForm before building a <ul> sub-navi.

    <xsl:if test="current()/node/@nodeTypeAlias != 'jobPost' or @nodeTypeAlias != 'jobForm'">

    This works if the child items are only ever one of each type, but when the child items include both types it bombs and displays the lot.

    Any ideas where I'm going wrong?

    Thanks,
    Barney

  • BarneyHall 141 posts 210 karma points
    Jan 19, 2010 @ 19:58
    BarneyHall
    0

    Sorry that was the wrong statement (I'm going round in circles with trial and error)... apologies for any confusion.

    <xsl:if test="current()/node/@nodeTypeAlias != 'jobPost' and current()/node/@nodeTypeAlias!='jobForm'">

    Like I say, it works when there's only jobPosts as child nodes, but if I publish a jobForm as a child also, it stops excluding the jobPosts and displays all of the child nodes.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 19, 2010 @ 21:10
    Thomas Höhler
    0

    Try something like this:

    <xsl:if test="count(current()/node [@nodeTypeAlias='jobPost' or @nodeTypeAlias='jobForm']) != 0">

    hth, Thomas

  • BarneyHall 141 posts 210 karma points
    Jan 20, 2010 @ 07:48
    BarneyHall
    0

    Thanks Thomas, but unfortunately that doesn't work either.

    This is driving me nuts. I think it has something to do with child nodes being a combination of both types of nodeTypeAlias but I just don't know XSLT well enough to work around it.

    Perhaps I should look out for the parent type instead and not run the list if it identifies a particular type, which would jobArea in this case?

  • Harald Ulriksen 207 posts 249 karma points
    Jan 20, 2010 @ 08:04
    Harald Ulriksen
    0

    I've got a setup with nodeTypeAlias Itinerary which can have child nodes of type Notifiaction, Budget, SegmentGroup. To retrieve only SegmentGroup based on exclusion I can use the following select

    //node[@nodeTypeAlias='Itinerary']/node[(@nodeTypeAlias = 'Budget' or @nodeTypeAlias = 'Notification') = 0]

     

    This can be rewritten to list itineraries without Budget or Notification children

    //node[@nodeTypeAlias='Itinerary' and node[(@nodeTypeAlias = 'Budget' or @nodeTypeAlias = 'Notification') = 0]]

     

     

     

    Replace //node with $currentPage or other start context.

    I can highly recommend testing xpath statements using sketchpad. Download from http://pgfearo.googlepages.com/downloads. Open your data\umbraco.config and enter your xpath in the middle blank textbox.

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 20, 2010 @ 09:36
    Thomas Höhler
    0

    Hi Barney, I have just tested my code with our intranet and it works like a charm. Please be sure that you don't have a typo for the node types in it or a logical problem with the current() parameter (e.g. you are on a false node or something).

    Herre my used code to check if there is a level2 node with one of the two doctypes:

    <xsl:if test="count($currentPage/ancestor-or-self::node [@level = 1]/node [@nodeTypeAlias = 'dtTest' or @nodeTypeAlias = 'dtTest']) != 0">

    Cheers, Thomas

  • BarneyHall 141 posts 210 karma points
    Jan 20, 2010 @ 10:55
    BarneyHall
    0

    Thomas, thanks for your patient help here :)

    This is working but the opposite way round, and seems to exclude everything but the node types defined in your statement.

    So I can make this work as the only child nodes I want displayed are what I'm defining as normalPage types. So I added node types I wanted to see to your statement instead. Now my jobPost and jobForm types are not displayed - exactly the result I wanted so thank you very much.

    I'm just curious now as to whether if there was a way of reversing it so that only the defined node types are excluded rather than included? Obviously this isn't crucial now, just interested...

    Cheers again!
    Barney

    ps - Harald thanks for your help too but that one was a bit over my head :)

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 20, 2010 @ 11:03
    Thomas Höhler
    1

    Glad I could help...

    But to your question: I have made something for our intranet:

    I defined a param which contains all the unwanted document types not to show in our menu:

    <xsl:param name="nodeTypes">dtAdmin;dtTest;dtTermin;</xsl:param>

    after that I am searching for all nodes which are not from any document type defined in the param

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(data [@alias='umbracoNaviHide']) != '1' and contains($nodeTypes, concat(@nodeTypeAlias, ';')) = false]">

    so this is an excluding, sorry thought you were searching for an including...

    Cheers, Thomas

  • BarneyHall 141 posts 210 karma points
    Jan 20, 2010 @ 11:10
    BarneyHall
    0

    That's really useful.. nice one. Thanks

  • BarneyHall 141 posts 210 karma points
    Sep 15, 2010 @ 14:58
    BarneyHall
    1

    Strangley found my old post when searching for a way to do this with the new schema.

    Seems this is really easy now.

    To select everything except your node type...

    select="* [not(local-name() = 'your-nodeTypeAlias-name')]"

    Barney

Please Sign in or register to post replies

Write your reply to:

Draft