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.
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
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
is working on a reply...