Copied to clipboard

Flag this post as spam?

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


  • David W. 159 posts 284 karma points c-trib
    Oct 06, 2010 @ 16:00
    David W.
    0

    Or-operator in for-each

    Hello,

     

    I'm looking to iterate through nodes of a particular set of document types.

    My cuurent xslt looks like this: 

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

    That works great, but I would also like to add another documenttype to the clause, I was hoping for something like this:

    <xsl:for-each select="$currentPage/[StandardPage | AnotherPage]/ancestor-or-self::* [@level=1]/* [@isDoc and string(umbracoNaviHide) != '1'] ">

    But that does not work. Any ideas?

    Thanks.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 06, 2010 @ 16:14
    Chriztian Steinmeier
    1

    Hi Sledger, 

    It actually doesn't matter because you're going up to level one, so you can just leave it out:

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@level=1]/*[@isDoc][not(umbracoNaviHide = 1)] ">
    - Just in case you're just wondering how to do the other thing:
    <xsl:for-each select="$currentPage/*[self::StandardPage or self::AnotherPage]/ancestor-or-self::*[@level=1]/*[@isDoc][not(umbracoNaviHide) = 1]">

    /Chriztian

  • David W. 159 posts 284 karma points c-trib
    Oct 07, 2010 @ 17:49
    David W.
    0

    Thanks for the markup. It sort of works, but gave me some unwanted consequences. As i suck on xslt (really need to take a training course!) I'm gonna go with another approach altogheter.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Oct 08, 2010 @ 12:27
    Thomas Höhler
    0

    I have a similiar approach but for excluding not including subnodes, but it can easily be reversed like this:

    1. I defined a param listing the document types to include:

    <xsl:param name="nodeTypes">Admin;Test;</xsl:param>

    2. Then I have the for-each with the filtering:

    <xsl:for-each select="$currentPage/ancestor-or-self::Frontpage/* [@isDoc and string(umbracoNaviHide) != '1' and contains($nodeTypes, concat(local-name(), ';')) = true]">

    With local-name you get the nodename (without namespace) so you can compare strings to it

    hth, Thomas

     

  • Ernst Utvik 123 posts 235 karma points
    Oct 08, 2010 @ 12:58
    Ernst Utvik
    0

    Since my problem is similar to yours I'll take the liberty to continue your post ;)

    Could anyone tell me the correct way to write the following:

    <xsl:variable name="upcomingEvents" select="($calendar/descendant/*/CalendarEvent [@isDoc and umbraco.library:DateGreaterThanOrEqualToday(./calEventDate)]"/>

    cheers

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 08, 2010 @ 13:11
    Chriztian Steinmeier
    0

    Hi Ernst - it's best if you create a new topic for stuff like this, but here you go:

    <xsl:variable name="upcomingEvents" select="$calendar//CalendarEvent[umbraco.library:DateGreaterThanOrEqualToday(calEventDate)]" />

    (You don't really need the @isDoc check if you know the DocumentType name, unless it's very generic)

    /Chriztian

  • Ernst Utvik 123 posts 235 karma points
    Oct 08, 2010 @ 13:30
    Ernst Utvik
    0

    Great stuff Chriztian :) Thanx a bunch.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies