{ public function getMatchXPath() { return '//*[@tal:attributes]'; } public function handleMatch($node) { $attr = $node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes'); // mask ;;, explode on ;, inside loop restore $attr = str_replace(';;', '__DBLSEMI__', $attr); $attr_pieces = explode(';', $attr); foreach ($attr_pieces as $attr) { $attr = str_replace('__DBLSEMI__', ';', $attr); $attr = trim($attr); if (strpos($attr, ' ') === FALSE) { throw new Exception(' attr misdefined'); } list($attr, $as) = explode(' ', $attr, 2); $append = strpos($attr, '+') === FALSE ? '' : $node->getAttribute(trim($attr, '+')) . ' '; $attr = trim($attr, '+'); $c = $this->createLocalVariable(); // we can't put raw PHP into the dom, or it will get escaped $str = $this->processTales($as, $c . ' = %s;'); $php_inst = PXHTMLTemplate::php()->register($str . 'echo htmlspecialchars(' . $c . '); unset(' . $c . ');'); $node->setAttribute($attr, $append . $php_inst); } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalAttributes_PXHTMLNode', PXHTMLTemplate::TAL_ATTRIBUTES);
<?php class ChipInclude_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//chip:include'; } public function handleMatch($node) { $PXHTMLTemplate = new PXHTMLTemplate(); $xtn = $node->getAttribute('xtn') ? '.' . $node->getAttribute('xtn') : '.php'; $cdata = $node->getAttribute('cdata') ? $node->getAttribute('cdata') : FALSE; $dom = $PXHTMLTemplate->parse(chip($node->getAttribute('file'))->getFilePath() . $xtn, TRUE, $cdata); // collect all things under the PXHTML root in new_dom, and // attach them as an appendChild statement $xpath = new DOMXPath($dom); $results = $xpath->query('/pxhtml:root'); $results = $results->item(0)->firstChild; // transfer all of the nodes from the include into the document at the include point while ($results) { $new_node = $this->importNode($results); $node->parentNode->insertBefore($new_node, $node); $results = $results->nextSibling; } $node->parentNode->removeChild($node); } } PXHTML::registerNS('pxhtml', 'http://xml.felocity.com/namespaces/pxhtml'); PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipInclude_PXHTMLNode', PXHTMLTemplate::PREPROCESSING_COMPLETE);