(: to produce legal and validable XHTML ... :)
declare option saxon:output "method=xml";
declare option saxon:output "doctype-public=-//W3C//DTD XHTML 1.0 Strict//EN";
declare option saxon:output "doctype-system=http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
declare option saxon:output "indent=yes";

(: remove all whitespace nodes from elements of the input tree :)
declare function local:strip-space($element){
    element {local-name($element)} {
        $element/@*,
        for $child in $element/node()
        return if ($child instance of text() and normalize-space($child)='')
               then ()
               else if ($child instance of element()) 
                    then local:strip-space($child)
                    else $child
    }
};

declare function local:root($root,$uri){
    <html>
        <head>
            <title>HTML compaction of "{replace($uri,'.*/(.*)','$1')}"</title>
        </head>
        <body>
            <ul>
                {local:element($root)}
            </ul>
        </body>
    </html>
};

declare function local:attribute($attribute){
    concat(" ",local-name($attribute),'="',$attribute,'"')
};

declare function local:element($element){
    <li>
        <b>{local-name($element)}</b>
        {for $attr in $element/@*
            return local:attribute($attr),
         if (count($element/*)=0) (: single text node ?:)
         then concat(" ",data($element))
         else <ul> { 
               for $child in $element/(*|text()) (: possible mixed node :)
                  return if($child instance of element())
                         then local:element($child)
                         else local:text($child)
            } </ul>
         }
    </li>    
};

declare function local:text($text){
    <li>{$text}</li>
};

(:  change the namespace of a subtree starting at an element 
    adapted from Priscilla Walmsley, XQuery, O'Reilly, p. 258 :)
declare function local:change-element-ns-deep($element,$new-ns){
    element {QName($new-ns,local-name($element))} {
        $element/@*,
        for $child in $element/node()
        return if ($child instance of element())
               then local:change-element-ns-deep($child,$new-ns)
               else $child
    }
};

local:change-element-ns-deep( (: put the whole tree in the XHTML namespace :) 
    local:root(local:strip-space(/*),document-uri(/)),
    "http://www.w3.org/1999/xhtml")