|
xquery version "1.0";
|
|
|
|
declare function local:out_rowd($top as node(),$out_rowc,$out_rowc_i,$out_rowb,$out_rowb_i,$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
{
|
|
for $out_rowd at $out_rowd_i in let $inVar := $out_root/sa return $inVar
|
|
where (
|
|
(
|
|
let $c := $out_rowd/c[1]
|
|
return (
|
|
if (fn:count($c) = 0) then ('') else (
|
|
if ($c/@xsi:nil['true']) then ('') else ($c/text()))
|
|
)
|
|
) = (
|
|
let $c := $out_rowc/c[1]
|
|
return (
|
|
if (fn:count($c) = 0) then ('_789odtMissing') else (
|
|
if ($c/@xsi:nil['true']) then ('_osdt987Null') else ($c/text()))
|
|
)
|
|
)
|
|
)
|
|
return (
|
|
element rowd {
|
|
element d { $out_rowd/d[1]/text() }
|
|
}
|
|
)
|
|
};
|
|
|
|
declare function local:out_rowc($top as node(),$out_rowb,$out_rowb_i,$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
{
|
|
for $out_rowc at $out_rowc_i in let $inVar := $out_root/sa return $inVar
|
|
where (
|
|
(
|
|
let $b := $out_rowc/b[1]
|
|
return (
|
|
if (fn:count($b) = 0) then ('') else (
|
|
if ($b/@xsi:nil['true']) then ('') else ($b/text()))
|
|
)
|
|
) = (
|
|
let $b := $out_rowb/b[1]
|
|
return (
|
|
if (fn:count($b) = 0) then ('_789odtMissing') else (
|
|
if ($b/@xsi:nil['true']) then ('_osdt987Null') else ($b/text()))
|
|
)
|
|
)
|
|
)
|
|
return (
|
|
element rowc {
|
|
element c { $out_rowc/c[1]/text() }
|
|
, local:out_rowd($top,$out_rowc,$out_rowc_i,$out_rowb,$out_rowb_i,$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
}
|
|
)
|
|
};
|
|
|
|
declare function local:out_rowb($top as node(),$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
{
|
|
for $out_rowb at $out_rowb_i in let $inVar := $out_root/sa return $inVar
|
|
where (
|
|
(
|
|
let $a := $out_rowb/a[1]
|
|
return (
|
|
if (fn:count($a) = 0) then ('') else (
|
|
if ($a/@xsi:nil['true']) then ('') else ($a/text()))
|
|
)
|
|
) = (
|
|
let $a := $out_rowa/a[1]
|
|
return (
|
|
if (fn:count($a) = 0) then ('_789odtMissing') else (
|
|
if ($a/@xsi:nil['true']) then ('_osdt987Null') else ($a/text()))
|
|
)
|
|
)
|
|
)
|
|
return (
|
|
element rowb {
|
|
element b { $out_rowb/b[1]/text() }
|
|
, local:out_rowc($top,$out_rowb,$out_rowb_i,$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
}
|
|
)
|
|
};
|
|
|
|
declare function local:out_rowa($top as node(),$out_root,$out_root_i)
|
|
{
|
|
let $out_sa_distinct := ( for $out_sa_a in fn:distinct-values($out_root/sa/a) return $out_root/sa[a=$out_sa_a][1])
|
|
let $out_sa_distinct :=( for $n in (1 to count($out_sa_distinct))
|
|
return $out_sa_distinct[$n][not(some $node in $out_sa_distinct[position() < $n] satisfies $node is .)])
|
|
for $out_rowa at $out_rowa_i in let $inVar := $out_sa_distinct return $inVar
|
|
order by $out_rowa/a[1]
|
|
return (
|
|
element rowa {
|
|
element a { $out_rowa/a[1]/text()},
|
|
element e {$out_rowa/e[1]/text()},
|
|
local:out_rowb($top,$out_rowa,$out_rowa_i,$out_root,$out_root_i)
|
|
})
|
|
};
|
|
|
|
declare function local:out_root($top as node())
|
|
{
|
|
for $out_root at $out_root_i in let $inVar := $top return $inVar
|
|
return (
|
|
element root { local:out_rowa($top,$out_root,$out_root_i) }
|
|
)
|
|
};
|
|
|
|
let $xml := fn:doc("file:///C:/test/test_xml_1k.txt")/root
|
|
return (
|
|
local:out_root($xml)
|
|
)
|