you could use a boolean type as="xs:boolean" and return true() or false() to make all future checks easier ie. $flatModeException = 'true' could simply be $flatModeException