Take the 2-minute tour ×

I have two XML files, which contain information on a document. I need to create a DOT graph based on the information in these files.


    <layout-unit id="lay-1.01" xref="u-1.01 u-1.02 u-1.03"/>
    <layout-unit id="lay-1.02" xref="u-1.04 u-1.05 u-1.06 u-1.07 u-1.08">
    <layout-unit id="lay-1.03" xref="u-1.09"/>
    <layout-unit id="lay-1.04" xref="u-1.10 u-1.11 u-1.12"/>
    <layout-unit id="lay-1.05" xref="u-1.13 u-1.14 u-1.15 u-1.16"/>


 <segment id="s-1.01" xref="u-1.01"/>
 <segment id="s-1.02" xref="u-1.02"/>
 <segment id="s-1.03" xref="u-1.03"/>
 <segment id="s-1.04" xref="u-1.04"/>
 <segment id="s-1.05" xref="u-1.05"/>
 <segment id="s-1.06" xref="u-1.06"/>
 <segment id="s-1.07" xref="u-1.07"/>
 <segment id="s-1.08" xref="u-1.08"/>
 <segment id="s-1.09" xref="u-1.09"/>
 <segment id="s-1.10" xref="u-1.10"/>
 <segment id="s-1.11" xref="u-1.11"/>
 <segment id="s-1.12" xref="u-1.12"/>
 <segment id="s-1.13" xref="u-1.13"/>
 <mini-segment id="s-1.14" xref="u-1.14"/>
 <mini-segment id="s-1.15" xref="u-1.15"/>
 <mini-segment id="s-1.16" xref="u-1.16"/>
<rst-structure root="s-1.01">
    <span id="span-1.01" nucleus="s-1.01" satellites="span-1.02" relation="elaboration"><title xref="s-1.09"></title></span>
    <span id="span-1.02" nucleus="s-1.02" satellites="s-1.03" relation="elaboration"/>
    <span id="span-1.03" nucleus="s-1.01" satellites="span-1.04" relation="enablement"/>
    <span id="span-1.04" nucleus="s-1.04" satellites="span-1.05" relation="enablement"/>
    <multi-span id="span-1.05" nuclei="span-1.08 span-1.06" relation="sequence"/>
    <span id="span-1.06" nucleus="s-1.06" satellites="span-1.07" relation="elaboration"></span>
    <multi-span id="span-1.07" nuclei="s-1.07 s-1.08" relation="restatement"></multi-span>
    <span id="span-1.08" nucleus="s-1.05" satellites="s-1.10 span-1.09" relation="elaboration"/>
    <span id="span-1.09" nucleus="s-1.11" satellites="span-1.10" relation="nonvolitional-result"/>
    <span id="span-1.10" nucleus="s-1.12" satellites="span-1.11" relation="elaboration"/>
    <mini-span id="span-1.11" attribute="s-1.14 s-1.15 s-1.16" attribuend="s-1.13" relation="class-ascription"/>

For creating the DOT graph, I have an XQuery script that fetches the data in rhetoric.xml, transforms it into DOT and sorts the graph into subgraphs according to layout.xml.

The graph is shown below.

DOT graph

I use the @xref attribute to select the relevant data in both files, as exemplified below:

declare function local:add-subgraphs($rhetoric, $layout) {
for $layout-unit-id in $layout/segmentation/layout-unit/@id
let $layout-unit-xrefs := tokenize($layout/segmentation/layout-unit[@id = $layout-unit-id]/@xref, " ")

let $rst-id := $rhetoric/segmentation/segment/@id
let $segment := $rhetoric/segmentation/segment[@xref = $layout-unit-xrefs and @id = $rst-id]/@id

I then begin to populate the DOT graph by going through the different elements under rhetoric/rst-structure:

let $add-edges-nucleus := for $span-id in $rhetoric/rst-structure/span[@nucleus = $segment]/@id
let $nucleus := tokenize($rhetoric/rst-structure/span[@id = $span-id]/@nucleus, " ")
return concat('"', $nucleus, '" ', $arrow, ' "', $span-id, '"', ';', $newline)

As you can see, the $segment variable is used to define which spans belong under a certain subgraph.

The problem emerges with this instance in rhetoric.xml:


In this case, I cannot use the $segment variable to select the span to be included in the subgraph, because it is structured differently than the span elements.

Consider, for instance, the segments s-1.07 and s-1.08, which should be included under lay-1.02, but instead remain outside of the subgraph in the above illustration.

Any ideas on how to define additional criteria to deal with the multi-span elements, in order to place them under the correct subgraph?

share|improve this question
add comment

1 Answer

If I understand correctly, you are trying to select the nucleus or nuclei attribute from either the span or multi-span element that matches a given span-id.

The following expression does just that:

$rhetoric/rst-structure/(span|multi-span)[@id = $span-id]/(@nucleus|@nuclei)

| is the XQuery union operator. Given your XML, this will only match a span or a multi-span element (the same applies to the nucleus/nuclei attributes).

Alternately, you could select any element with a matching span-id:

$rhetoric/rst-structure/*[@id = $span-id]/(@nucleus|@nuclei)
share|improve this answer
add comment

Your Answer


