Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何使用XQuery创建点图?_Xml_Xquery_Dot - Fatal编程技术网

Xml 如何使用XQuery创建点图?

Xml 如何使用XQuery创建点图?,xml,xquery,dot,Xml,Xquery,Dot,我需要基于以下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-chun

我需要基于以下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>
这将导致此可视化图形:

使用XQuery解析布局块布局结构元素及其可能的子元素的布局根元素,并返回要在点图中使用的id和外部参照属性的最佳方法是什么


我是XQuery的新手,尝试过各种方法;我认为我需要连接每个元素中的id和xref值,以便为DOT生成所需的标记。

以下查询可能会有所帮助(使用BaseX和Saxon进行测试):

声明变量$nl:='
;';
声明函数本地:ref($root){
串接((
对于$root/layout块中的$c
返回(
concat(“,$root/@id,”--“,$c/@id,“;”,$nl),
本地:参考($c)
),
本地:叶($root)),“”)
};
声明函数本地:叶($root){
对于$root/layout-leaf中的$c
返回concat(“,$root/@id,”--“,$c/@xref,“;”,$nl)
};
(:可选:let$doc:=doc(“doc.xml”):)
让$doc:=文档{
}
让$root:=$doc/布局结构/*
返回海螺(
'图形',$root/name(),''{',$nl,
本地:ref($root),
'}')

Dot有一种XML语法,称为DotML。我发现生成DotML比直接生成Dot更容易。详情如下:


非常感谢,@christian grun!我得到了大部分代码,但是您能在第二个函数声明中引导我完成这一部分吗:
return(concat(“”,$root/@id,“--”,$c/@id,“;”,$nl),local:ref($c)),local:leaf($root)),“)在concat函数之后,代码到底做了什么?不知道从哪里开始…你到底需要了解什么?没关系,在读了一点函数定义之后,我就明白了-这对我来说是一件新鲜事!不过,非常感谢!
graph "layout-root" {
"layout-root" -- "header-text";
"header-text" -- "lay-1.01";
"header-text" -- "lay-1.02";
"layout-root" -- "lay-1.03";
}
declare variable $nl := '&#10;';

declare function local:ref($root) {
  string-join((
    for $c in $root/layout-chunk
    return (
      concat('  "', $root/@id, '" -- "', $c/@id, '";', $nl),
      local:ref($c)
    ),
    local:leaf($root)), "")
};

declare function local:leaf($root) {
  for $c in $root/layout-leaf
  return concat('  "', $root/@id, '" -- "', $c/@xref, '";', $nl)
};

(: Alternative: let $doc := doc("doc.xml") :)
let $doc := document {
  <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> }
let $root := $doc/layout-structure/*
return concat(
  'graph "', $root/name(), '" { ' , $nl,
  local:ref($root),
'}')