--- site_map.module	2008-03-09 03:03:47.000000000 +0000
+++ site_map.module.patched	2008-03-09 03:01:51.000000000 +0000
@@ -482,17 +482,22 @@
     // in $term->depth since the $last_depth.
     if ($term->depth > $last_depth) {
       for ($i = 0; $i < ($term->depth - $last_depth); $i++) {
-        $output .= '<ul>';
+        $output .= "\n<ul>";
       }
     }
+    else if ($term->depth == $last_depth) {
+      $output .= "</li>\n";
+    }
     else if ($term->depth < $last_depth) {
       for ($i = 0; $i < ($last_depth - $term->depth); $i++) {
-        $output .= '</ul>';
+        $output .= "\n</li>\n</ul>\n</li>\n";
       }
     }
     // Display the $term.
-    $output .= '<li>';
+    $output .= "\n<li>";
+
     $term->count = taxonomy_term_count_nodes($term->tid);
+
     if ($term->count) {
       if ($cat_depth < 0) {
         $output .= l($term->name, taxonomy_term_path($term), array('title' => $term->description));
@@ -511,10 +516,7 @@
       $output .= ' '. theme('site_map_feed_icon', url("taxonomy/term/$term->tid/$rss_depth/feed"));
       $output .= (module_exists('commentrss') ? ' '. theme('site_map_feed_icon', url("crss/term/$term->tid"), 'comment') : '');
     }
-
-
-
-    $output .= "</li>\n";
+    
     // Reset $last_depth in preparation for the next $term.
     $last_depth = $term->depth;
   }
@@ -522,7 +524,7 @@
   // Bring the depth back to where it began, -1.
   if ($last_depth > -1) {
     for ($i = 0; $i < ($last_depth + 1); $i++) {
-      $output .= '</ul>';
+      $output .= "\n</li>\n</ul>";
     }
   }
   $output .= "</div>\n";
