Generic conversion assuming no missing cells

If there are no missing elements in any rows, a faster algorithm is possible.

XQuery

declare variable $base := "/db/apps/wikibook/data/";
declare function local:table-to-html($root) {
let $headers  :=  $root/*[1]/*/name(.)
return
  <table border="1">
    <thead>
      <tr>
        {for $header in $headers
         return <th>{$header}</th> 
        }
      </tr>
    </thead>
    <tbody>
      {for $row in $root/*
       return
         <tr>
            {for $col in $row/*
             return <td>{$col/text()}</td> 
        } 
         </tr>
      }
    </tbody>
   </table>
 };

let $doc := doc(concat($base,"empdept.xml"))/*
return local:table-to-html($doc)

Result

EmpNo Ename Job MgrNo HireDate Sal Comm DeptNo
7369 SMITH CLERK 7902 1993-06-13 800 0 20
7499 ALLEN SALESMAN 7698 1998-08-15 1600 300 30
7521 WARD SALESMAN 7698 1996-03-26 1250 500 30
7566 JONES MANAGER 7839 1995-10-31 2975 20
7698 BLAKE MANAGER 7839 1992-06-11 2850 30
7782 CLARK MANAGER 7839 1993-05-14 2450 10
7788 SCOTT ANALYST 7566 1996-03-05 3000 20
7839 KING PRESIDENT 1990-06-09 5000 0 10
7844 TURNER SALESMAN 7698 1995-06-04 1500 0 30
7876 ADAMS CLERK 7788 1999-06-04 1100 20
7900 JAMES CLERK 7698 2000-06-23 950 30
7934 MILLER CLERK 7782 2000-01-21 1300 10
7902 FORD ANALYST 7566 1997-12-05 3000 20
7654 MARTIN SALESMAN 7698 1998-12-05 1250 1400 30