for $profiles in collection('/db/Profiles/RuntimeResource')//Resource
let $scopes := string-join( $profiles/Scopes//Scope/text(), ';')
let $subtype := $profiles//Resource/Profile/Category/text()
<RES_SUBTYPE ISdefault =''/> 
    return 
    <Resource>
        {$profiles//Resource/ID}
        <Type>{$profiles//Resource/Type/text()}</Type>
        <SubType>{$subtype}</SubType>
        <Scopes>{$scopes}</Scopes>
        <Name>{$profiles//Resource/Profile/Name/text()}</Name>
    </Resource>