for $x in doc ($doc_name)/ProcessValueTrace/Trace
return
<Trace>
{
for $y in $x/DtsResult
let $bb:=for $xx in $y/DtsRequest where (contains($xx/PDU, string($pdu_byte_pattern))) return $xx
return
(: my problem is from here down. i have 3 outputs - first the beginning tag and a few tags i just output

if (empty($bb)) then
""
else
return
<DtsResult>
{ $y/LogicalLink }
{ $y/ComPrimitive }
(: than i output some selected tags:)
for $z in $y/DtsRequest
where (contains($z/PDU, string($pdu_byte_pattern)))
return
$z
(: than i output the close tag - in case i had something before it:)
if (empty($bb)) then
""
else
</DtsResult>
</Trace>
I tried to place each of the 3 outputs in {..} but i kept getting error. I played a little with the {} but i didn't get them and the output right. I appreciate your help.
Best regards.
Paul