Dear BaseX folks,

constructing elements, I encounter a problem with namespaces which I do not understand. Is it a bug or do I overlook something?

To reproduce the problem you need to create an XML file "doc.xml" with this content:

<doc xmlns="http://basex.org/simply/the/best">
    <foo bar="1"> 
        <peng/>
    </foo>
</doc>

And here's the query:

declare namespace f="http://basex.org/does/its/thing";

declare function f:pretty($n as node())
        as node()? {
    typeswitch($n)
    case document-node() return document {$n/node() ! f:pretty(.)}
    case element() return
        element {node-name($n)} {
            in-scope-prefixes($n) ! namespace {.} {namespace-uri-for-prefix(., $n)},
            $n/@* ! f:pretty(.),
            $n/node() ! f:pretty(.)
        }
    default return $n
};    

let $doc := doc('doc.xml')
return f:pretty($doc)

What I get is this error:

Stopped at C:/projects/tableman/prototype/thieme-showcase/xq/demo-namespace-problem.xq, 8/33:
[XQDY0102] Duplicate declaration of namespace 'http://basex.org/simply/the/best'.

Stack Trace:
- C:/projects/tableman/prototype/thieme-showcase/xq/demo-namespace-problem.xq, 11/33
- C:/projects/tableman/prototype/thieme-showcase/xq/demo-namespace-problem.xq, 11/33
- C:/projects/tableman/prototype/thieme-showcase/xq/demo-namespace-problem.xq, 6/63
- C:/projects/tableman/prototype/thieme-showcase/xq/demo-namespace-problem.xq, 17/16

Strangely enough, you do not get the error if you copy the contents of doc.xml into the query:

let $doc := <doc .../>
return f:pretty($doc)

You also do not get the error if you remove the @bar attribute in the document.

Kind regards,
Hans-Jürgen