Tinderbox Forum

Descendant-or-self?

I can collect the values of a given attribute for all the descendants of particular note (with the collect function and the descendants group designator)

What is the best way of prepending the attribute value of the parent note itself to that list ?

(rather as in XPath’s descendant-or-self axis, or simply as in prepending, or cons-ing, a single value to the start of an existing list)

Just add the value.

$MySet = $MyString; $MySet=$MySet + collect(descendants, $MyString)

The edge case to watch out for is that + has a different meaning as a string operation and as a set or list operation.

1 Like

FWIW a brief JS sketch of using all the XPath axes in Tinderbox, including descendant-or-self, in another thread: