for $outer in collection("/db/Properties")//Document
let $scopes := string-join( $outer//Document/Data/child::*[local-name()='Scope']/text(), ';')
where $outer//Document/Data/child::*[local-name()='ServiceClass']/text() eq '<RES_SUBTYPE/>'
return 
    <WSResource>
        {$outer//Document/ID}
        {$outer//Document/Source}
        {$outer//Document/SourceKey}
        <ServiceClass>{$outer//Document/Data/child::*[local-name()='ServiceClass']/text()}</ServiceClass>
        <ServiceName>{$outer//Document/Data/child::*[local-name()='ServiceName']/text()}</ServiceName>
        <SubType>{$outer//Document/Data/child::*[local-name()='ServiceClass']/text()}</SubType>
        {$outer//Document/TerminationTimeHuman}
        {$outer//Document/LastUpdateHuman}
        <RI>{$outer//Document/Data/child::*[local-name()='RI']/text()}</RI>
        <Type>WSResource</Type>
        <scopes>{$scopes}</scopes>
    </WSResource>