XQuery: create a new sequence and return it
<p>What I am trying to achieve is to add values from <code>$stationsSequence</code> into a new sequence, <code>$newSequence</code> and then return <code>distinct-values</code> in the sequence. I "naively" tried to do it with an if statement like this:</p>

<pre><code>let $stationsSequence := fn:doc("stations.xml")//station
let $newSequence := ()

for $station in $stationsSequence 

    return

        if ( fn:starts-with($station, "W") or fn:starts-with($station, "B") )
        then
            fn:insert-before($newSequence , last(), $station)
        else ()

        fn:distinct-values($newSequence)
</code></pre>

<p>What would be the correct way to do this?
Thank you</p>