Although these XSLT variables are called variables, they're not variables in the traditional sense of procedural programming languages like C or Java.
element is used to declare a local or global variable.
Note: The variable is global if it's declared as a top-level element, and local if it's declared within a template.
Rather, this code fragment defines $foo as the collection of all the things created by the block.
In particular, B does not say "Look through the data nodes and if *any* of them satisfy the test ["contains(elements/ element A '1234) or contains(elements/package/id '55) or contains(elements/category/id, '67)" or contains(............."], then assign the value of "1" to B, otherwise assign "0." Rather, what this code does is say "Create a temporary document in memory.