1 Reply Latest reply on May 19, 2013 2:22 AM by abhay kumar

    XQuery Question: FLWOR expressions?

      Help. I am a bit confused and stuck on this question regarding XQuery.

      Here's the XML for it.
      URL: http://s3.amazonaws.com/spark-public/db/docs/courses-noID.xml

      Return course numbers of courses that have the same title as some other course.

      Please explain to me how to obtain the answer STEP-BY-STEP and the ANSWER. :) Good luck.

      - Nathan
        • 1. Re: XQuery Question: FLWOR expressions?
          abhay kumar
          Here is what you can try:-
          Lets say the input is assigned to $out variable

          let $output := $out//*:Title (:in this step get the list of all titles:)

          let $outputNew:= <t>{for $x in 1 to count($out//*:Title)
                                          for $y in  $x+1 to count($out//*:Title)
                                               where $output[$x]=$output[$y]
                                             }</t> (:through this loop get the list of all titles which count of more than one, loop through the sequence and then find if two elements match means that their occurenceis more than once:)
               let $moreThanOnetitles:= fn:data($outputNew//*:Title) (:get the sequence of all titles with count more than one)
               let $finalOut:=      <temp>{
               for $x in $out//*:Course
               let $title:= data($x/*:Title)
                         where some $titleinseq in $moreThanOnetitles satisfies deep-equal($titleinseq,$title)
          return $finalOut

          (:through this FLOWR loop through all courses and find if their titles is there in the sequence of $morethantitles then return the title and coursenumber:)