your code looks OK although a bit scary for something that's a one-liner in xslt, I think an xquery analogue of xsl:copy ought to be pretty high on the xquery 1.x wish list! As others have said I don't think that in-scope-prefixes can ever return duplicate strings, and your code worked (with saxon) on the example you posted. David