13095379e19fa2f9c0851d8bf852cac4906137b9
[xhtml-compiler.git] / XHTMLCompiler / DOMFilter / IEConditionalComments.php
blob13095379e19fa2f9c0851d8bf852cac4906137b9
1 <?php
3 /**
4 * Enables Internet Explorer style conditional comments to survive XML
5 * parsing by implementing a custom xc:ie-condition attribute to attach
6 * to elements.
7 */
8 class XHTMLCompiler_DOMFilter_IEConditionalComments extends XHTMLCompiler_DOMFilter
11 protected $name = 'IEConditionalComments';
12 protected $xcAttr = array('ie-condition');
14 public function process(DOMDocument $dom, $page, $manager) {
16 $nodes = $this->query( "//*[@xc:ie-condition]" );
18 foreach ($nodes as $node) {
19 $condition = $this->confiscateAttr($node, $this->ns, 'ie-condition');
20 if ($condition) {
21 $sxml = simplexml_import_dom($node);
22 $code = $sxml->asXml();
23 $comment = "[if $condition]>$code<![endif]";
24 $parent = $node->parentNode;
25 $parent->replaceChild($dom->createComment($comment), $node);