forked from eXist-db/xqlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_schemas.xq
52 lines (47 loc) · 1.27 KB
/
generate_schemas.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import module namespace file = "http://expath.org/ns/file";
import module namespace xqdoc = "http://www.zorba-xquery.com/modules/xqdoc";
declare namespace xqd = "http://www.xqdoc.org/1.0";
declare function local:description-summary($description as element(xqd:description)*)
as element(p)
{
let $text := local:text($description)
let $text := normalize-space($text)
let $text := if(string-length($text) gt 300) then substring($text, 1, 300) || "..." else $text
return
<p>{$text}</p>
};
declare function local:text($nodes)
as xs:string?
{
string-join(
for $node in $nodes
return
if($node instance of text()) then
$node
else
local:text($node/node())
, " ")
};
variable $processed := ();
{|
for $file in file:list("modules", true(), "*.xsd")
return {
trace($file, "file");
variable $source := file:read-text("modules/" || $file);
variable $schema := parse-xml($source);
variable $ns := $schema/xs:schema/@targetNamespace/string();
variable $description := $schema/xs:schema/xs:annotation/xs:documentation/text();
variable $r :=
{
$ns : {
"doc": $description,
"docUrl": "http://www.28msec.com/modules/"
}
};
$processed := ($processed, $ns);
if(count($processed[. eq $ns]) = 1) then
$r
else
()
}
|}