protected static function notExists(DOMXPath $xpath, ChariotContext $context, ChariotTagRepository $repository)
 {
     $nodes = array();
     if (isset($context->currentNode)) {
         $nodes = $xpath->query('*[@c:notExists]', $context->currentNode);
     } else {
         $nodes = $xpath->query('//*[@c:notExists]');
     }
     foreach ($nodes as $child) {
         $existsValue = $child->getAttributeNodeNS(self::URN, 'notExists')->nodeValue;
         $child->removeAttributeNS(self::URN, 'notExists');
         if ($context->hasAttribute($existsValue)) {
             $child->nodeValue = '';
             $child->parentNode->removeChild($child);
             continue;
         }
         $ctx = $context->createChild();
         $ctx->currentIndex = -1;
         $ctx->currentValue = null;
         $ctx->currentNode = $child;
         $repos = clone $repository;
         foreach ($repos as $r) {
             $r->start($ctx, $repository);
         }
     }
 }
 public function start(ChariotContext $context, ChariotTagRepository $repository)
 {
     $rootDocument = $context->getGlobalAttribute('document');
     $rootElement = $rootDocument->createElement('div');
     $xpath = new DOMXPath($rootDocument);
     $xpath->registerNamespace('c', ChariotTagHandler::URN);
     $context->setGlobalAttibute('xpath', $xpath);
     $context->setGlobalAttibute('rootElement', $rootElement);
     foreach ($xpath->query('//*[@class="dummy"]') as $dummyNode) {
         $dummyNode->parentNode->removeChild($dummyNode);
     }
     $parsed = false;
     foreach ($xpath->query('//*[@c:template]') as $child) {
         $templateName = $child->getAttributeNodeNS(ChariotTagHandler::URN, 'template')->nodeValue;
         $child->removeAttributeNS(ChariotTagHandler::URN, 'template');
         $className = '';
         if ($child->hasAttribute('class')) {
             $className = $child->getAttribute('class');
         }
         $child->setAttribute('class', $className . ' ' . $templateName);
         $ctx = $context->createChild();
         $ctx->currentNode = $child;
         $ctx->currentTemplateName = $templateName;
         foreach ($repository as $handler) {
             $handler->start($ctx, $repository);
         }
         $rootElement->appendChild($child);
         $parsed = true;
     }
     if ($parsed) {
         // remove all nodes
         $rootDocument->removeChild($rootDocument->firstChild);
         // as root(first) element
         $rootDocument->appendChild($rootElement);
         // remove all chariot urn
         //foreach($rootDocument->getElementsByTagNameNS(ChariotTagHandler::URN, '*') as $node){
         //}
     }
     return $rootDocument;
 }
 public function start(ChariotContext $context, ChariotTagRepository $repository)
 {
     $xpath = $context->getGlobalAttribute('xpath');
     $nodes = array();
     if (isset($context->currentNode)) {
         $nodes = $xpath->query('*[@c:foreach]', $context->currentNode);
     } else {
         $nodes = $xpath->query('//*[@c:foreach]');
     }
     foreach ($nodes as $child) {
         $foreachValue = $child->getAttributeNodeNS(self::URN, 'foreach')->nodeValue;
         $child->removeAttributeNS(self::URN, 'foreach');
         $children = array();
         $replacement = $context->getAttribute($foreachValue);
         foreach ($replacement as $index => $replaceValue) {
             foreach ($child->childNodes as $c) {
                 $clone = $c->cloneNode(true);
                 $ctx = $context->createChild();
                 $ctx->currentNode = $clone;
                 $ctx->currentIndex = $index;
                 $ctx->currentValue = $replaceValue;
                 $repos = clone $repository;
                 foreach ($repos as $r) {
                     $r->start($ctx, $repository);
                 }
                 $children[] = $clone;
             }
         }
         // remove all children
         $child->nodeValue = '';
         // append new clone nodes
         foreach ($children as $_cloneChild) {
             $child->appendChild($_cloneChild);
         }
     }
 }