I'd like to get a list of doctors without hill patient. This is my solution but at the end it prints twice the same value and moreover the values printed aren't right.
Can someone highlight what I am doing wrong?
declare function local:outRange($x as element()) as xs:boolean{ boolean( $x/Value < $x/MinVal or $x/Value > $x/MaxVal ) }; (: List of all doctors :) let $alldoc := distinct-values(//Exam/Doctor) (: List of doctors with at least 1 hill patient :) for $exam in //Exam let $dochill := $exam/Doctor where some $outc in $exam/Outcome satisfies local:outRange($outc) return ( (: List of doctors without hill patients :) let $ok := ( for $doc in $alldoc return if( some $doc2 in $dochill satisfies $doc2 = $doc) then () else( $doc ) ) return <HealthyDoctors> { $ok }</HealthyDoctors> ) A small sample of XML is this:
<Exam> <Outcome> <Value>90</Value> <MinVal>100</MinVal> <MaxVal>150</MaxVal> </Outcome> <Outcome> <Value>15</Value> <MinVal>1</MinVal> <MaxVal>20</MaxVal> </Outcome> <Outcome> <Value>1</Value> <MinVal>1</MinVal> <MaxVal>5</MaxVal> </Outcome> <Doctor>Stack Overflow</Doctor> </Exam> <Exam> <Outcome> <Value>190</Value> <MinVal>100</MinVal> <MaxVal>150</MaxVal> </Outcome> <Outcome> <Value>10</Value> <MinVal>1</MinVal> <MaxVal>5</MaxVal> </Outcome> <Doctor>Stack Overflow</Doctor> </Exam> <Exam> <Outcome> <Value>120</Value> <MinVal>100</MinVal> <MaxVal>150</MaxVal> </Outcome> <Outcome> <Value>4</Value> <MinVal>1</MinVal> <MaxVal>5</MaxVal> </Outcome> <Doctor>Health</Doctor> </Exam> <Exam> <Outcome> <Value>120</Value> <MinVal>100</MinVal> <MaxVal>150</MaxVal> </Outcome> <Outcome> <Value>10</Value> <MinVal>1</MinVal> <MaxVal>5</MaxVal> </Outcome> <Doctor>OneHill</Doctor> </Exam> What I am expecting as a result is:
<HealthyDoctors> <Doctor>Health</Doctor> </HealthyDoctors>
No comments:
Post a Comment