xmlxpathattributesparent-childfreeplane

How do I join matching attributes of all child nodes in Freeplane parent node?


Freeplane files are XML and they apparently use groovy scripts, but I can't work out how to return an attribute (as a text string) using a formula in a parent node. The main help page is here: https://docs.freeplane.org/scripting/Formulas.html

Let's say I have the following tree structure:

rootNode
    |        +---child0
    |        |
    +--------+---child1
             |
             +---child2

Now, I want to add attributes to the rootNode and the children such that:

rootNode:
    |  +->attr[sum=children.sum(0){ it['size'].num0 }]
    |  +->attr[colours=children.join(";"){ it['colour'].text }]
    |
    |        +---child0:
    |        |     +->attr[colour='red']
    |        |     +->attr[size=3]
    |        |
    +--------+---child1:
             |     +->attr[colour='green']
             |     +->attr[size=4]
             |
             +---child2:
                   +->attr[colour='blue']
                   +->attr[size=5]

where rootNode['sum'] == 12 and rootNode['colours'] == 'red;green;blue'.

The sum operation works on the numeric child attributes: enter image description here

...but I don't know how to join the text attributes of all the children: enter image description here

I have tried:

=children.join(";"){ it['colour'].text }
=children.join(";"){ it['colour'] }
=children.text(){ it['colour'].join(";") }
=children.gettext(){ it['colour'].join(";") }
=children(){ it['colour'].join(";") }
=children.details(){ it['colour'].join(";") }

...and so far the only formula that does not result in an error:

=children.each{ it['colour'].text }.join(';')

enter image description here

Any other suggestions?


Solution

  • You need to use collect to create a new list of colours:

    =children.collect{it['colour']}.join(";")