Functions taken from XQuery