BEA's implementation of XQuery does not support recursion. If you try it, you get an exception like:
weblogic.xml.query.exceptions.XQuerySystemException: {bea-err}SYS006: Function {lib:DsTest/WorkItemHierarchy/hierarchy}factorial is recursive; this is not supported (sorry)
at weblogic.xml.query.operators.UserDefinedFunction.codeGenRecursiveFunction(UserDefinedFunction.java:174)
at weblogic.xml.query.runtime.core.RecFuncIterator.fetchNext(RecFuncIterator.java:69)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:109)