Actually I found my answer.

Your snippet worked perfectly if I remove the /@audience from the order by 
statement.

for $audience in $these-docs//ec:audience
order by $audience
return $audience/fn:string()

Now to dedupe
... I am sure there's a fn:distinct-values function I can use somewhere... I'll 
come back with a question about that if I run into one.

Thanks again!

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Kari Cowan
Sent: Thursday, July 30, 2015 12:32 PM
To: MarkLogic Developer Discussion <general@developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] Sorting and De-duping

That's an improvement, thanks.

But I think what I am seeing is that it iterates through the doc results and 
returns
Doc1  : ordered audience list 1
Doc2  : ordered audience list 2
...

Is there a better way to build out the list in one fell swoop so I can get them 
all together?


From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [mailto:general-boun...@developer.marklogic.com] On Behalf Of Danny Sokolsky
Sent: Thursday, July 30, 2015 11:52 AM
To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] Sorting and De-duping

The result of your search is a sequence of documents.  I think you want to 
xpath down to audience for each document in your FLOWR.  Something like:

for $audience in $these-docs//ec:audience
order by $audience/@audience
return $audience/fn:string()

-Danny

From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [mailto:general-boun...@developer.marklogic.com] On Behalf Of Kari Cowan
Sent: Thursday, July 30, 2015 11:44 AM
To: general@developer.marklogic.com<mailto:general@developer.marklogic.com>
Subject: [MarkLogic Dev General] Sorting and De-duping

I have a query that returns a group of records.

I want to display a sorted list of results of a node called 'audience' - there 
can be multiple audience nodes in a document.

Here's a snippet and result list, to put it in context.

Am I missing something obvious?


xquery version "1.0-ml";
declare namespace ec = "http://www.alm.com/event-calendar";;
let $directory:="/data-sources/editorial-calendar/"

let $these-docs:=
cts:search(
  xdmp:directory($directory),
  cts:and-query((
    cts:element-attribute-range-query(xs:QName("ec:MaterialsDueDate"), 
xs:QName("date"), ">=", xs:date(fn:current-date()) ),
    cts:element-query(xs:QName("ec:approval_status"),cts:word-query("true"))
  ))
)

for $audiences in $these-docs
order by fn:data($audiences//ec:audience/@audience)
return $audiences//ec:audience/text()


>>
Consulting
Entertainment
Food and Beverage
Consulting
Health Care/Medical
Insurance
Automotive
Real Estate
Transportation/Aviation
Education
Food and Beverage
Health Care/Medical

________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media 
Company, is a leading provider of news and information for the legal and 
commercial real estate markets. ALM's market-leading brands include The 
American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, 
Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.
________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media 
Company, is a leading provider of news and information for the legal and 
commercial real estate markets. ALM's market-leading brands include The 
American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, 
Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.



_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to