Can you suggest the best way to do that? I tried casting it as a string in the
return but that doesn’t do the job (and doesn’t show any error).
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
fn:string(fn:string-join(json:transform-to-json( fn:doc($events/doc-uri),
$config ),",")),
"]}")
From: [email protected]
[mailto:[email protected]] On Behalf Of Christopher Hamlin
Sent: Tuesday, November 17, 2015 9:37 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] $counter < i -- I might be overthinking
this
json:transform-to-json is returning a document node. fn:concat takes a bunch
of things and casts them to xs:string. fn:string-join takes strings
specifically.
So two possibilities:
1. You need to change the docs to strings before doing string-join.
2. Make sure the strings are in a sequence, not "loose" like for fn:concat.
/ch
On Tue, Nov 17, 2015 at 12:30 PM, Kari Cowan
<[email protected]<mailto:[email protected]>> wrote:
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),
"]}")
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general