Hi Ankit,
Am 23.03.2015 um 16:23 schrieb ankit kumar:
I am trying to get all distinct start element '/products/p:category/start' nodes of a big file. I have written a query which is given below. It is taking to long to get the result. I am attaching the query info and the xml file.
After Running couple of minutes, I stopped the execution.
Query is trying to get all the distinct start elements
There are 3 lac category elements.
the function `functx:distinct-nodes($nodes)` distinguishes the elements of its input sequence by their *node identity*, not the string contents. Since all of the nodes you iterate over are distinct, this will not do what you want. It also has very bad performance because each node is compared to all preceding ones.
If you want to get all distinct text contents, you can just use `fn:distince-values($seq)`:
declare namespace p="a:b:c"; fn:distinct-values(/products/p:category/start)
Result:
10-2-2012 10-5-2011 10-2-2009
If you also want one of the XML elements with those text contents you can use `group by`:
declare namespace p="a:b:c"; for $start in /products/p:category/start group by $date := $start/string() return <unique n="{count($start)}">{ $start[1] }</unique>
Result:
<unique n="100000"> <start xmlns:p="a:b:c">10-2-2012</start> </unique> <unique n="100000"> <start xmlns:p="a:b:c">10-5-2011</start> </unique> <unique n="100000"> <start xmlns:p="a:b:c">10-2-2009</start> </unique>
Hope that helps, Leo