Hi Pragya,
To simply sort the list items, you will need a for loop with an order by
clause. To catch the first item of a sorted list, you will need to wrap this
for loop within braces and put [1] behind it. But it might be easier to
rephrase it a bit: return from a group of list items with same title and text
only the one with highest score value. You can do this in plain xquery, but it
might perform badly:
for $item in //list
let $same-items := //list[title eq $item/title and text eq $item/text]
let $max-score := max($same-items/score/number())
order by $item/score descending
where $item/score/number() eq $max-score
return
$item
It might speed things up if you add title, text and score as element indexes,
and list as fragment root, or try to express this logic with cts functions..
Kind regards,
Geert
>
drs. G.P.H. (Geert) Josten
Consultant
Daidalos BV
Hoekeindsehof 1-4
2665 JZ Bleiswijk
T +31 (0)10 850 1200
F +31 (0)10 850 1199
mailto:[email protected]
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit e-mailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit
bericht kunnen geen rechten worden ontleend.
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Pragya Kapoor
> Sent: woensdag 21 juli 2010 5:30
> To: [email protected]
> Subject: [MarkLogic Dev General] FW: XML node Comapare and sort query
>
> Hi ,
>
> I have the below xml, in which I need to do the following:
>
>
>
> If the value of both title and text element are same, sort
> those list element based on score attribute
>
> For e.g.:
>
> Here the value of title and text for 1st and 3rd list element
> are same, so these two should be sort based on score and
> display the list which has the highest score and discard
> others. How can I achieve this?
>
>
>
>
>
> Desired output:
>
> <list>
>
> <title>abcd</title>
>
> <text>abcd</text>
>
> <score>2</score>
>
> </list>
>
>
>
> -----XML-----
>
> <result>
>
> <list>
>
> <title>abcd</title>
>
> <text>abcd</text>
>
> <score>1</score>
>
> </list>
>
> <list>
>
> <title>efgh</title>
>
> <text>efgh</text>
>
> <score>3</score>
>
> </list>
>
> <list>
>
> <title>abcd</title>
>
> <text>abcd</text>
>
> <score>2</score>
>
> </list>
>
> <result>
>
>
>
> Thanks,
>
> Pragya
>
>
>
>
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general