Skip to content

Instantly share code, notes, and snippets.

@KitWallace
Created August 21, 2012 23:52
Show Gist options
  • Save KitWallace/3420598 to your computer and use it in GitHub Desktop.
Save KitWallace/3420598 to your computer and use it in GitHub Desktop.
invert a stick (a tree wih no branches) Challenge 2
declare function local:stick_to_seq($stick) {
if ($stick)
then (name($stick),local:stick_to_seq($stick/*))
else ()
};
declare function local:seq_to_stick($seq) {
if (exists($seq))
then element {$seq[1]} {local:seq_to_stick(subsequence($seq,2))}
else ()
};
declare function local:invert($stick) {
local:seq_to_stick(reverse(local:stick_to_seq($stick)))
};
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