Tinderbox Forum

How to refer to a child note by name

I want to use

sum_if(children(XXX), $Attribute==“Value”,1)

to count some of the children of note XXX. Now: XXX is not unique. I want to use the code in XXX’s parent’s action, but there might be another XXX somewhere else in the document. I also don’t know the absolute path of XXX. In other situations I can use


to refer to a specific child by name but sum_if doesn’t seem to understand that.
Any ideas?


This is a bit of a strange one. The following action will work:

var xxxPath;
xxxPath = $Path + "/XXX";

But neither of these work:

sum_if(children($Path + "/XXX"),$Attribute=="Value",1);
$MyString = $Path + "/XXX";

My guess is that the argument to children cannot be a full Tinderbox expression, but only a literal string, and that furthermore, Tinderbox vars are fully evaluated to literal strings as part of the action-code evaluation. But @eastgate is the one to say for sure.

Not tested but this my be a situation where eval() is needed, i.e. something like sum_if(children(eval($Path + "/XXX")),$Attribute=="Value",1);. The logic here being that eval generates a string literal that works in offset reference to children.

Doesn’t seem to work in my tests. I wouldn’t expect it to, if my understanding is correct, since eval(...) is also a Tinderbox expression, so if children needs a literal string here eval won’t help matters.

1 Like

Thanks, the extra var declaration did the trick for me. Tinderbox certainly is a strange beast but I’m slowly finding my way.

A full path always begins with a /. So

sum(children(/Notes), $Width)

is the width of all the children inside the top-level container named Notes.

@eastgate, given that I have the path of the note that I want in an attribute, is assigning that attribute to an intermediate var the only way to use that path in a designator? I.e.,

var path;
path = $Attribute;
sum(children(path), $Width)

Or is there a more direct method?

When we write


things get tricky. When we evaluate the expression, to what is this bound? this is bound in sum(), sum_if(). find(), collect() and related constructs to the note that is being examined, not to the note that is performing the rule or action, so $Path is the path to that note, not the path to the action note!

You want

sum(children($Path(that)), …)

1 Like

Aha! Thanks for that really helpful clarification, which I’ll try and weave appropriately into the aTbRef** notes.

** currently dark due to DNS snafu, but to return.