I guess I need your help.
I have an XML file structured this way:
<root>
<source id="1"/>
<source id="2"/>
<source ..... />
<element id="e1">
<connection from_id="1">
</element>
<element id="e7">
<connection from_id="1">
</element>
<element id="e2">
<connection from_id="e2">
</element>
<element id="e3">
<connection from_id="e2">
</element>
<element id="e4">
<connection from_id="e3">
</element>
<element id="e5">
<connection from_id="2">
</element>
<element id="e6">
<connection from_id="3">
</element>
</root>
Now, what I've tried to accomplish is to count() the number of nodes (more specific: element-nodes), that are somehow connected to each source-node, even if they are connected via another element node. So for this example: source-node 1: 5 source-node 2: 1 source-node 3: 1
If tried multiple approaches, including functions and recursion, but I wasn't able to manage this task. From my daily java-programmers perspective I just miss a variable or so to save some intermediate results.
So my question: How can I do this without any intermediate results?