title: Style unstyled links with DOM and xpath
body: <p>For a system I am building I am defining a general <code>style</code> stored in <code>LINKSTYLE</code> that should be applied to <code>a</code> elements that are not yet styled (inline). I am not very experienced with the <code>DOMDocument</code> or <code>xpath</code> and I can't figure out what is going wrong.</p>
  
  <p>Thanks to Gordon I've updated my code:</p>
  
  <pre><code>libxml_use_internal_errors(true);    
  
  $html  = '&lt;a href="#"&gt;test&lt;/a&gt;'.
           '&lt;a href="#" style="border:1px solid #000;"&gt;test2&lt;/a&gt;';
  
  $dom    = new DOMDocument();
  $dom-&gt;loadHtml($html);
  $dom-&gt;normalizeDocument();  
  $xpath = new DOMXPath($dom);
  
  foreach($xpath-&gt;query('//a[not(@style)]') as $node)
      $node-&gt;setAttribute('style','border:1px solid #000');
  
  return $html;
  </code></pre>
  
  <p>With this <strong>updated</strong> code I receive no more errors, however the <code>a</code> element does not get styled.</p>