将类应用于DOM中的父元素?

        <li id="weather" class="widget-container widget-dark-blue">
            <h3 class="widget-title">Weather</h3>
            <?php include (TEMPLATEPATH . '/widgets/weather.php'); ?>
        </li>

weather.php does a curl request to a weather service and returns a table. With the DomDocument Class I read the values inside of the td's. I'm applying a classname of the current weather condition to a div.weather.

<?php

require_once('classes/SmartDOMDocument.class.php');

$url = 'some/domain...';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);

$str = curl_exec($curl);

$dom = new SmartDOMDocument();
$dom->loadHTML($str);
$xpath = new DOMXPath($dom);

$tds = $xpath->query('//div/table/tr/td');

foreach ($tds as $key => $cell) {
    if ($key==1) {
        $condition = $cell->textContent;
        //$cell->parentNode->setAttribute('class', 'hello');
        echo "<div class='weather " . strtolower($condition) ."'>";
        ...

?>

Everything works fine. My one and only question is, is there a PHP way of applying the classname $condition to the list-item that holds the information? So instead of having a class with the $condtion inside of my li#weather I'd like to have the li#weather the class.

<li id="weather" class="widget-container widget-dark-blue $condition">

Is there any way I can apply the $condition class to the list that hold's everything. I could easily do it with javascript/jquery. However I wonder if there is some serverside solution.

thank you

Maybe you could try somthing like :

$parent = $cell->parentNode;

while ($parent->tagName != 'li')
{
    $parent = $parent->parentNode;
}

$class = $parent->getAttribute('class');
$parent->setAttribute('class', $class . ' ' . strtolower($condition));