Yeah, fn:last() doesn’t work inside a FLWOR that way. Best to just do a count upfront, and compare with that..
Cheers, Geert From: <[email protected]<mailto:[email protected]>> on behalf of Indrajeet Verma <[email protected]<mailto:[email protected]>> Reply-To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Date: Tuesday, November 17, 2015 at 7:46 AM To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Subject: Re: [MarkLogic Dev General] $counter < i -- I might be overthinking this Cowan, There is a function fn:last() which returns an integer value that represents the number of items in the current context. Please refer https://docs.marklogic.com/fn:last. See if that works for you. Another approach could be, you can get the count of your results and add the condition like $counter < $count or $counter = $count whatever you needed. Regards, Indy On Tue, Nov 17, 2015 at 10:00 AM, 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:=("{"events":[", 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
