Thanks for the tip Michael I might rewrite the query now.
I also have a problem whit this query that makes a xml document that is to be used whit C# I want to remove the chapter nodes in the answere but when I do that I cant get the query to work Here is the query.
declare namespace tf = 'http://namespaces.softwareag.com/tamino/TaminoFunction'
declare namespace ft = 'http://www.w3.org/2002/04/xquery-operators-text'
declare namespace xs = 'http://www.w3.org/2001/XMLSchema'
<TREENODES>{
for $bib in input()/dtbook
let $x:=$bib/descendant::p
let $z :=
for $y in $x
where ft:text-contains($y, 'java')
return $y
where $z
return <TreeNode> { attribute
inoId{tf:getInoId($bib)},
attribute docname{tf:getDocname(root($bib))},
attribute matchCount{count($z)},
attribute Text{$bib/head/title},
<chapter>{
for $f in $z/parent::*[self::level1]
let $j:=$f/descendant::p
let $h :=
for $g in $j
where ft:text-contains($g, 'java')
return $g
where $h
return <TreeNode>{
attribute matchCountP{count($h)},
attribute Ancestor{local-name($f/parent::node())},
attribute Level{local-name($f)},
attribute Text{$f/h1/text()},
<chapter2>{
for $a in $h/parent::*[self::level2]
let $u :=$a/descendant::p
let $i :=
for $l in $u
where ft:text-contains($l, 'java')
return $l
where $i
return <TreeNode>{
attribute matchCountP{count($i)},
attribute Ancestor{local-name($a/parent::node())},
attribute Level{local-name($a)},
attribute Text{$a/h2/text()},
<chapter3>{
for $q in $i/parent::*[self::level3]
let $t :=$q/descendant::p
let $e :=
for $c in $t
where ft:text-contains($c, 'java')
return $c
where $e
return <TreeNode>
{
attribute matchCountP{count($e)},
attribute Ancestor{local-name($q/parent::node())},
attribute Level{local-name($q)},
attribute Text{$q/h3/text()}
}</TreeNode>
}</chapter3>
}</TreeNode>
}</chapter2>
}</TreeNode>
}</chapter>
}</TreeNode>
sort by( xs:int(@matchCount) descending)
}</TREENODES>
And also I am kinda thinking that this query could be done better but This ia what I have come up whit by now Do you got any suqestion to how I could optimaze this query.
Thanks for any help.
#webMethods#API-Management#Tamino