public static function render(common_report_Report $report) {
        
        $stack = new SplStack();
        $renderingStack = new SplStack();
        $traversed = array();
        
        $stack->push($report);
        $nesting = 0;
        
        while ($stack->count() > 0) {
            
            $current = $stack->pop();
            
            if (in_array($current, $traversed, true) === false && $current->hasChildren() === true) {
                $nesting++;
                // -- Hierarchical report, 1st pass (descending).
                
                // Repush report for a 2ndpass.
                $stack->push($current);
                
                // Tag as already traversed.
                $traversed[] = $current;
                
                // Push the children for a 1st pass.
                foreach ($current as $child) {
                    $stack->push($child);
                }
            }
            else if (in_array($current, $traversed, true) === true && $current->hasChildren() === true) {
                $nesting--;
                // -- Hierachical report, 2nd pass (ascending).
                
                // Get the nested renderings of the current report.
                $children = array();
                foreach ($current as $child) {
                    $children[] = $renderingStack->pop();
                }
                
                $renderingStack->push(self::renderReport($current, $children, $nesting));
            }
            else {
                // -- Leaf report, 1st & single pass.
                $renderingStack->push(self::renderReport($current, array(), $nesting, true));
            }
        }
        
        return $renderingStack->pop();
    }