Hi, Let me show you a simple example that shows strange behaviour of parse-xml() function: ----------------------------------------------- declare function local:transform($nodes as node()*) as item()* { for $node in $nodes return typeswitch($node) case text() return parse-xml-fragment($node) case element(b) return element b {local:transform($node/node())} default return local:transform($node/node()) }; let $textdoc := <doc><a>content 1</a> <b><a>content 2</a></b> </doc> let $doc := <doc>{ for $node in $textdoc/node() return local:transform($node) }</doc> let $doc2 := <doc>{ for $node in $doc/node() return $node }</doc> return $doc ---------------------------------------------------- After running it on baseX 7.6 the result is: $doc = <doc> <a>content 1</a> <b> <a>content 2</a> </b> </doc> but it differs from doc2: $doc2 = <doc> <b> <a>content 2</a> </b> <a>content 1</a> </doc> Why does using parse-xml() function change the order of the elements? I ran this simple code on zorba and eXist (using util:parse() function) and $doc2 was the same as $doc. Regards Bartosz Marciniak