Copied to clipboard

Flag this post as spam?

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


  • Pete Miller 8 posts 26 karma points
    Apr 14, 2009 @ 23:50
    Pete Miller
    0

    Using XPATH to retreive a node based on two child nodes

    Hi all,

    I'm by no means an XPATH expert. I'm trying to walk-up the current node's tree, and retreive any node that has two elements, one with any value and one with a specific value ('1').

    We've come up with the following, and it seems to work, but it seems a little clunky to have to select nodes where the first condition is true, then of that list select nodes where the second condition is true, then select the parent node...

    ...call me a perfectionist but I'd like to know the best way to do this!

    ancestor-or-self::*/data[@alias='PropertyKey1' and text() != ''][last()]/../data[@alias='PropertyKey2' and text() = '1'][last()]/..

    By the way, this is being passed in as a string to the Umbraco API that selects a node based on an XPath from the current node.

    Thanks,

    Pete

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 15, 2009 @ 00:26
    Lee Kelleher
    0

    Hi Pete,

    How's about this?

    [code]ancestor-or-self::node[data[@alias='PropertyKey1'] != '' and data[@alias='PropertyKey2'] = '1'][/code]

    Let me know if that works. (I'm on Twitter too @leekelleher)

    Cheers,
    - Lee

Please Sign in or register to post replies

Write your reply to:

Draft