I suspect that when you say “entities” you mean “elements”.
This is a typical example of a recursive query. Recursive queries are a big problem for all database systems because the performance is open-ended. In the XQuery language, arbitrary recursive queries can be expressed using user-defined functions, but these are not yet available in Tamino.
It might be easier to code this in XSLT, or perhaps even in a low-level procedural language using DOM interfaces. There are many published algorithms for graph traversal that you can apply to this problem (the optimum solution depends on how dense the linkages are in your graph) and they are all expressed in procedural code, so this is a case where a procedural language such as Java may be more appropriate than a declarative language such as XQuery or XSLT, if you want control over the performance.
Michael Kay
#webMethods#Tamino#API-Management