I have the current structure;
Item 1
- Subitem 1
- Subitem 2
- Subitem 3
- - Sub subitem 1
- - Sub subitem 2
- - Sub subitem 3
- - etc
I have a field that is only defined on “Item 1”. Let’s call it ‘Header’.
When i am on “Item 1” its easy enough to extract this value, but what about when i am on the other items? Is there a way i can go through the tree (up) until i find a field called ‘Header’ and it has a value, and then stop and use this as a reference point in my sub items?
If you want to look up the tree and find the closest element that contains a Header attribute with a value, something like this should work.
This uses the
ancestoraxis to look up the tree and the xpath expression looks for any element with a Header attribute who’s value is not empty.A second filter is used to evaluate the last one. If there is more than one ancestor that has a
@Headerwith a value, the last one would be the closest to the context node, because the result is in document order.EDIT: An alternative way to find the same results, leveraging the fact that
ancestoraxis returns in reverse document order would be to put the filter criteria in the predicate for theancestoraxis step, select the first one(closest match to the context node), and then step into the @Header: