Cross processor portability, using function-available
Portability function-available tips
Two other suggestions for how to tackle this:
(a) put the processor-dependent code in an external XML entity, and use an EntityResolver to bring in the right version of the external entity at stylesheet compile-time.
(b) write a processor-dependent stylesheet overlay that imports the main logic of the stylesheet and overrides the processor-specific parts (for example, the global variable "foo" in your example below). Use this overlay as the nominated stylesheet for your transformation.