I need to create a DOT graph on the basis of the following XML:
<layout-structure>
<layout-root id="layout-root">
<layout-chunk id="header-text">
<layout-leaf xref="lay-1.01"/>
<layout-leaf xref="lay-1.02"/>
</layout-chunk>
<layout-leaf xref="lay-1.03"/>
</layout-root>
</layout-structure>
I want to use DOT to visualize the dependencies between the different layout-chunk and layout-leaf elements, which are identified using either id or xref attributes, depending on the element type.
The result I want is given below in DOT:
graph "layout-root" {
"layout-root" -- "header-text";
"header-text" -- "lay-1.01";
"header-text" -- "lay-1.02";
"layout-root" -- "lay-1.03";
}
Which would result in this visualized graph:

What would be the best way to use XQuery to parse layout-root element for layout-chunk and layout-structure elements and their possible children, and returning the id and xref attributes to be used in the DOT graph?
I am a complete newbie in XQuery and have tried various approaches; I think I need to concatenate the id and xref values in each element, in order to produce the required markup for DOT.
The following query may help (tested with BaseX and Saxon):