Skip to content

Instantly share code, notes, and snippets.

@KitWallace
Created August 22, 2012 07:29
Show Gist options
  • Save KitWallace/3423421 to your computer and use it in GitHub Desktop.
Save KitWallace/3423421 to your computer and use it in GitHub Desktop.
Recursive invert a stick
declare function local:invert($stick) {
let $leaf := $stick//*[last()]
return local:invert1($leaf)
};
declare function local:invert1($leaf) {
if (exists($leaf))
then element {name($leaf)} {
local:invert1($leaf/..)
}
else ()
};
let $x := <a><b><c><d/></c></b></a>
return local:invert($x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment