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]> 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:=("{&#34;events&#34;:[",
>
> 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

Reply via email to