public function resolveTemplateLocation($validate = false)
    {
        if (($root = $this->getDocumentComponent()) !== null) {
            
            if ($root instanceof AssessmentItem && ($responseProcessing = $root->getResponseProcessing()) !== null && ($templateLocation = $responseProcessing->getTemplateLocation()) !== '') {
                
                if (Url::isRelative($templateLocation) === true) {
                    
                    $baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
                    $pathinfo = pathinfo($baseUri);
                    $basePath = $pathinfo['dirname'];
                    $templateLocation = Url::rtrim($basePath) . '/' . Url::ltrim($templateLocation);
                    
                    $doc = new XmlDocument();
                    $doc->load($templateLocation, $validate);
                    
                    $newResponseProcessing = $doc->getDocumentComponent();
                    
                    if ($newResponseProcessing instanceof ResponseProcessing) {
                        $root->setResponseProcessing($newResponseProcessing);
                    } else {
                        $msg = "The template at location '${templateLocation}' is not a document containing a QTI responseProcessing element.";
                        throw new XmlStorageException($msg, XmlStorageException::RESOLUTION);
                    }
                }
            }
        } else {
            $msg = "Cannot resolve template location before loading any file.";
            throw new LogicException($msg);
        }
    }