for $profiles in collection('/db/Profiles/GenericResource')//Resource, $wsresource in collection('/db/Properties')//Document
let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
let $subtype := $profiles//Resource/Profile/SecondaryType/text()
where $subtype = "GCUBECollection" and $profiles//Resource/ID eq $wsresource/SourceKey and $wsresource/Data//child::*[local-name()='Type']/string() eq 'gDocRead'
return
{$profiles//Resource/ID}
{$profiles//Resource/Type/text()}
{$subtype}
{$scopes}
{$profiles//Resource/Profile/Name/text()}
{$profiles//Resource/Profile/Body/CollectionInfo/creationTime/text()}
{$wsresource/LastUpdateHuman/text()}
{$wsresource//child::*[local-name()='Cardinality']/text()}