xquery version "3.1";
let $root := element {fn:node-name($e)}
   {$e/@*, 2 * fn:data($e)}

for $node in root($root)
return
  element root { root ($node)/text(), attribute root {'root'},
element not-root{attribute type{"root"}, root($root)}
}
