This discussion is archived
2 Replies Latest reply: Apr 23, 2012 7:34 AM by 667006 RSS

Basic doubt and problem with my query

932410 Newbie
Currently Being Moderated
Hi friends

I am pretty new to this xquery .I had to learn and implement it in my project.We have many rules to follow so basically i have an XML already provided.I need to work on several issues.When i am working i have come across different errors or very small minor problems.here is question1

1)i am trying to find the LArgest population in whole..Here is the quesry i am using

declare variable $xmldoc1:= doc("mondial-3.0.xml");
*<project>*
*{*
let $test := max($xmldoc1/mondial/country/@population)
for $a in $xmldoc1/mondial/country where  $a/encompassed/@continent ="f0_132" and $a/@population=$test
return
*<country>*
*{$a/name}*
*</country>*
*}*
*</project*



I am not able to display any thing but when i take out the condition $a/@population=$test out i am able to see all the name..

Help me friends ..THank you
  • 1. Re: Basic doubt and problem with my query
    odie_63 Guru
    Currently Being Moderated
    The query doesn't return anything because, most likely, the country with max population doesn't belong to the continent whose id = "f0_132", simple as that.

    Remove the following condition and see the difference :
    $a/encompassed/@continent ="f0_132"
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 2. Re: Basic doubt and problem with my query
    667006 Newbie
    Currently Being Moderated
    I think you'll be just fine changing the order of your two statements. As odie_63 already pointed out, the max population country is probably in another continent.
    You might want to try something like this:

    declare variable $xmldoc1:= doc("mondial-3.0.xml");
    <project>
    {
    for $a in $xmldoc1/mondial/country[encompassed/@continent ='f0_132']
    let $maxpop := max($a/@population)
    where $a/@population = $maxpop
    return
    <country>
    {$a/name}
    </country>
    }
    </project

    Good luck!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points