fn:string-join - I thought about that – tried it but it didn’t join each with 
the comma – it also didn’t give me any error.  That would have been the 
simplest had it worked; wouldn’t need the if statement at all.   I thought 
perhaps it’s not really a string, but documents that are transformed to JSON 
from XML? (not sure, that’s still going to return as a string I think).  Any 
idea why fn:string-join didn’t work?

So I tried the counter idea Gert suggested – this seems to work, as long as the 
ordering is ‘descending’ – if I switch it to ascending, it gets quirky – Is it 
using the native state not what I set?

let $outputJSON:=("{"events":[",
let $config := json:config("full"),
                $cx := map:put( $config, "whitespace", "ignore" )
let $count:= fn:count($search-this-partner/event)
for $events at $counter in $search-this-partner/event
 order by $events/EventStartDate/@date descending
  return if( $count > $counter ) then
   ( fn:concat(json:transform-to-json( fn:doc($events/doc-uri), $config ), 
","),"count: ", $count, "counter: ", $counter )
else
  ( json:transform-to-json( fn:doc($events/doc-uri), $config ), "else count: ", 
$count, "else counter: ", $counter),
"]}")



From: [email protected] 
[mailto:[email protected]] On Behalf Of Christopher Hamlin
Sent: Tuesday, November 17, 2015 5:59 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] $counter < i -- I might be overthinking 
this

Can fn:string-join help?  Join with ',', and glue on whatever you like before 
or after?

On Mon, Nov 16, 2015 at 11:30 PM, Kari Cowan 
<[email protected]<mailto:[email protected]>> wrote:
Is there any built-in component I can reference that would indicate in the loop 
below where $counter is less than the last item in the loop?

This would print the json for the return only when $counter=1, is simple way to 
know when $counter < LastItem?

let $outputJSON:=("{&#34;events&#34;:[",
let $config := json:config("full"),
                $cx := map:put( $config, "whitespace", "ignore" )
for $events at $counter in $search-this-partner/event
order by $events/EventStartDate/@date ascending
  return if($search-this-partner/event[$counter=1]) then
    fn:concat(json:transform-to-json( fn:doc($events/doc-uri), $config ), ",")
else
    "foo",
"]}")

>>
{"events":[
foo
Event object
foo
]}
________________________________
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
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general




_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to