The follow file is included in many of the XSLT Transform examples.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<!-- The show-node-as-table template creates a table out of the attributes and children of a node -->
<xsl:template name="show-node-as-table">
<xsl:param name="title"/>
<xsl:param name="node"/>
<xsl:variable name="columns">
<xsl:choose>
<xsl:when test="count($node/@*) <= 0">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count($node/@*)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<table>
<tr>
<th colspan="{$columns}">
<xsl:value-of select="$title"/>
</th>
</tr>
<tr>
<th colspan="{$columns}">
<xsl:value-of select="name($node)"/>
</th>
</tr>
<xsl:if test="text()">
<tr>
<td colspan="{$columns}">
<xsl:value-of select="."/>
</td>
</tr>
</xsl:if>
<tr>
<xsl:for-each select="$node/@*">
<th>
<xsl:value-of select="name()"/>
</th>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="$node/@*">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
<xsl:for-each select="$node/node()">
<tr>
<th>
<xsl:value-of select="name()"/>
</th>
<td>
<xsl:call-template name="show-node-as-table">
<xsl:with-param name="title"/>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!-- The show-result-set-as-table template creates a table out of a result-set -->
<xsl:template name="show-result-set-as-table">
<xsl:param name="title"/>
<xsl:param name="result-set"/>
<xsl:variable name="columns">
<xsl:choose>
<xsl:when test="count($result-set/row[1]/column) <= 0">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(rows[1]/column)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<table>
<xsl:if test="$title">
<tr>
<th colspan="{$columns}">
<xsl:value-of select="$title"/>
</th>
</tr>
</xsl:if>
<tr>
<xsl:for-each select="$result-set/row[1]/column">
<th>
<xsl:value-of select="@name"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="$result-set/row">
<tr>
<xsl:for-each select="column">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!-- The show-node-as-xml template creates a html encoded xml out of the attributes and children of a node -->
<xsl:template name="show-node-as-xml">
<xsl:param name="node"/>
<xsl:param name="indent"/>
<xsl:value-of disable-output-escaping="yes" select="$indent"/>
<xsl:text><</xsl:text>
<xsl:value-of select="name($node)"/>
<xsl:for-each select="$node/@*">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:for-each>
<xsl:text>></xsl:text>
<br/>
<xsl:text>
</xsl:text>
<xsl:if test="text()">
<xsl:value-of disable-output-escaping="yes" select="$indent"/>
<xsl:value-of select="."/>
<br/>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:for-each select="$node/node()">
<xsl:if test="name()!=''">
<xsl:call-template name="show-node-as-xml">
<xsl:with-param name="indent" select="concat($indent,'&nbsp;&nbsp;&nbsp;&nbsp;')"/>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
<xsl:value-of disable-output-escaping="yes" select="$indent"/>
<xsl:text></</xsl:text>
<xsl:value-of select="name($node)"/>
<xsl:text>></xsl:text>
<br/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>