I have at least XML, in which I need to do the following:
If both price Title and text elements are the same, sort those list elements based on the attribute of the score
For example: Here the value of the title and text for the 1 and 3th list element is the same, so these two Sort the scores on the score and display that list with the highest score and others Abandon
I can I get it?
Desired Output:
& lt; List & gt; & Lt; Title & gt; ABCD & lt; / Title & gt; & Lt; Text & gt; ABCD & lt; / Text & gt; & Lt; Score & gt; 2 & lt; / Score & gt; & Lt; / List & gt; ----- XML -----
& lt; Results & gt; & Lt; List & gt; & Lt; Title & gt; ABCD & lt; / Title & gt; & Lt; Text & gt; ABCD & lt; / Text & gt; & Lt; Score & gt; 1 & lt; / Score & gt; & Lt; / List & gt; & Lt; List & gt; & Lt; Title & gt; EFGH & lt; / Title & gt; & Lt; Text & gt; EFGH & lt; / Text & gt; & Lt; Score & gt; 3 & lt; / Score & gt; & Lt; / List & gt; & Lt; List & gt; & Lt; Title & gt; ABCD & lt; / Title & gt; & Lt; Text & gt; ABCD & lt; / Text & gt; & Lt; Score & gt; 2 & lt; / Score & gt; & Lt; / List & gt; & Lt; Results & gt;Let's assume that you correctly understand that you only return list nodes Where the title and text are the same and each value has nodes of those people who are the highest score. And since you tagged the "xquery" question, I think you want to do it in Exquire.
declare the local function: getHighScores (result as $ node) node () * as * $ $ same: = $ $ in $ result / list ($ i / title / Text () = $ i / text / text ()) Give $ i $ unique_titles: = fn: distinct-values ($ same / title / text ()) $ unique $ heading for $ heading ($ The result is $ $ / j title = $ heading $ $ / j for the number coming in $ j) [1]}; Give $ Xml: = & lt; Results & gt; & Lt; List & gt; & Lt; Title & gt; ABCD & lt; / Title & gt; & Lt; Text & gt; ABCD & lt; / Text & gt; & Lt; Score & gt; 1 & lt; / Score & gt; & Lt; / List & gt; & Lt; List & gt; & Lt; Title & gt; EFGH & lt; / Title & gt; & Lt; Text & gt; EFGH & lt; / Text & gt; & Lt; Score & gt; 3 & lt; / Score & gt; & Lt; / List & gt; & Lt; List & gt; & Lt; Title & gt; ABCD & lt; / Title & gt; & Lt; Text & gt; ABCD & lt; / Text & gt; & Lt; Score & gt; 2 & lt; / Score & gt; & Lt; / List & gt; & Lt; List & gt; & Lt; Title & gt; Abcdg & lt; / Title & gt; & Lt; Text & gt; Abcde & lt; / Text & gt; & Lt; Score & gt; 2 & lt; / Score & gt; & Lt; / List & gt; & Lt; / Results & gt; Local return: getHighScores ($ xml)
Comments
Post a Comment