次の XML ファイルに基づいて DOT グラフを作成する必要があります。
<layout>
<layout-structure>
<layout-root id="layout-root">
<layout-chunk id="header-text">
<layout-leaf xref="lay-1.01" location="row-1" area-ref="content"/>
<layout-leaf xref="lay-1.02" location="row-2" area-ref="content"/>
</layout-chunk>
<layout-leaf xref="lay-1.03" location="row-3" area-ref="content"/>
</layout-root>
<layout-root id="layout-root-two">
<layout-chunk id="header-text-two">
<layout-leaf xref="lay-1.04"/>
<layout-leaf xref="lay-1.05"/>
</layout-chunk>
</layout-root>
</layout-structure>
<realization>
<text xref="lay-1.01 lay-1.04"/>
<text xref="lay-1.02 lay-1.05"/>
<graphics xref="lay-1.03"/>
</realization>
<layout>
この目的のために、次のクエリを使用して、XML のレイアウト ルート要素ごとに DOT マークアップを生成します。
declare variable $newline := ' ';
declare variable $dotgraphics := '[shape="box", style="filled", color="#b3c6ed"]';
declare function local:ref($root) {
string-join((
for $chunk in $root/layout-chunk
return (
concat(' "', $root/@id, '" -- "', $chunk/@id, '";', $newline),
local:ref($chunk)
),
local:leaf($root)), "")
};
declare function local:leaf($root) {
for $leaf in $root/layout-leaf
return concat(' "', $root/@id, '" -- "', $leaf/@xref, '";', $newline)
};
declare function local:gfx($doc) {
for $layout-leafs in $doc//layout-leaf
let $graphics := $doc/realization//graphics
where $graphics[contains(@xref, $layout-leafs/@xref)]
return concat('"', $graphics/@xref, '" ', $dotgraphics, ';', $newline)
};
let $doc := doc("layout-data.xml")/layout
for $root in $doc/layout-structure/*
return string-join(('graph "', $root/@id, '" { ', $newline,
local:gfx($doc),local:ref($root),'}', $newline), "")
両方のレイアウト ルート要素に対するクエリの結果を以下に示します。
graph "layout-root" {
"lay-1.03" [shape="box", style="filled", color="#b3c6ed"];
"layout-root" -- "header-text";
"header-text" -- "lay-1.01";
"header-text" -- "lay-1.02";
"layout-root" -- "lay-1.03";
}
graph "layout-root-two" {
"lay-1.03" [shape="box", style="filled", color="#b3c6ed"];
"layout-root-two" -- "header-text-two";
"header-text-two" -- "lay-1.04";
"header-text-two" -- "lay-1.05";
}
ご覧のとおり、要素のタイプがgraphicsの場合、クエリは次の関数を使用して DOT マークアップの色と形状を変更します。
declare function local:gfx($doc) {
for $layout-leafs in $doc//layout-leaf
let $graphics := $doc/realization//graphics
where $graphics[contains(@xref, $layout-leafs/@xref)]
return concat('"', $graphics/@xref, '" ', $dotgraphics, ';', $newline)
};
ただし、これは最初のグラフ ( layout-rootという名前) にのみ表示されるはずですが"lay-1.03" [shape="box", style="filled", color="#b3c6ed"];
、2 番目のグラフ ( layout-root-twoという名前)の行も返すため、必要な結果は得られません。
layout-structure の下の各layout-rootの場合にグラフィック要素をチェックするように、関数をどのように変更すればよいですか?
変数$rootを使用して関数を呼び出そうとしましたが、静的エラーが発生します。
必要な結果を以下に示します。
graph "layout-root" {
"lay-1.03" [shape="box", style="filled", color="#b3c6ed"];
"layout-root" -- "header-text";
"header-text" -- "lay-1.01";
"header-text" -- "lay-1.02";
"layout-root" -- "lay-1.03";
}
graph "layout-root-two" {
"layout-root-two" -- "header-text-two";
"header-text-two" -- "lay-1.04";
"header-text-two" -- "lay-1.05";
}