<?php

include_once TOOLKIT . '/class.htmlpage.php';
$Page = new HTMLPage();
$Page->Html->setElementStyle('html');
$Page->Html->setDTD('<!DOCTYPE html>');
$Page->Html->setAttribute('xml:lang', 'en');
$Page->addElementToHead(new XMLElement('meta', NULL, array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8')), 0);
$Page->addStylesheetToHead(APPLICATION_URL . '/assets/css/symphony.css', 'screen', 30);
$Page->addStylesheetToHead(APPLICATION_URL . '/assets/css/symphony.frames.css', 'screen', 31);
$Page->setHttpStatus($e->getHttpStatusCode());
$Page->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$Page->addHeaderToPage('Symphony-Error-Type', 'xslt');
$Page->setTitle(__('%1$s &ndash; %2$s', array(__('Symphony'), __('XSLT Processing Error'))));
$Page->Body->setAttribute('id', 'fatalerror');
$div = new XMLElement('div', NULL, array('class' => 'frame'));
$ul = new XMLElement('ul');
$li = new XMLElement('li');
$li->appendChild(new XMLElement('h1', __('XSLT Processing Error')));
$li->appendChild(new XMLElement('p', __('This page could not be rendered due to the following XSLT processing errors:')));
$ul->appendChild($li);
$errors_grouped = array();
list($key, $val) = $e->getAdditional()->proc->getError(false, true);
do {
    if (preg_match('/^loadXML\\(\\)/i', $val['message']) && preg_match_all('/line:\\s+(\\d+)/i', $val['message'], $matches)) {
        $errors_grouped['xml'][] = array('line' => $matches[1][0], 'raw' => $val);
    } elseif (preg_match_all('/pages\\/([^.\\/]+\\.xsl)\\s+line\\s+(\\d+)/i', $val['message'], $matches) || preg_match_all('/pages\\/([^.\\/]+\\.xsl):(\\d+):/i', $val['message'], $matches)) {
        $errors_grouped['page'][$matches[1][0]][] = array('line' => $matches[2][0], 'raw' => $val);
    } elseif (preg_match_all('/utilities\\/([^.\\/]+\\.xsl)\\s+line\\s+(\\d+)/i', $val['message'], $matches)) {
        $errors_grouped['utility'][$matches[1][0]][] = array('line' => $matches[2][0], 'raw' => $val);
    } else {