This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data">
<table>
<xsl:apply-templates select="*[1]"/>
</table>
</xsl:template>
<xsl:template match="record[1]/*" priority="1">
<tr>
<th>
<xsl:value-of select="name()"/>
</th>
<xsl:call-template name="td"/>
</tr>
</xsl:template>
<xsl:template match="record/*" name="td">
<td>
<xsl:value-of select="."/>
</td>
<xsl:apply-templates select="following::*[count(../*)+1]"/>
</xsl:template>
</xsl:stylesheet>
Output:
<table>
<tr>
<th>id</th>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<th>name</th>
<td>David</td>
<td>Tully</td>
<td>Solai</td>
<td>Michael</td>
<td>Tony</td>
<td>Ray</td>
<td>Leeha</td>
</tr>
<tr>
<th>age</th>
<td>40</td>
<td>38</td>
<td>32</td>
<td>49</td>
<td>19</td>
<td>26</td>
<td>13</td>
</tr>
</table>
EDIT: Just to show that this could be a not so trivial question, what about an XML tree with a more relaxed schema (missing some fields in records)?
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="kElementByName" match="record/*" use="name()"/>
<xsl:template match="text()"/>
<xsl:template match="data">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="record/*[count(.|key('kElementByName',name())[1])=1]">
<tr>
<th>
<xsl:value-of select="name()"/>
</th>
<xsl:apply-templates select="../../record" mode="td">
<xsl:with-param name="pName" select="name()"/>
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template match="record" mode="td">
<xsl:param name="pName"/>
<td>
<xsl:value-of select="*[name()=$pName]"/>
</td>
</xsl:template>
</xsl:stylesheet>
With this input:
<data>
<record>
<id>1</id>
<name>David</name>
</record>
<record>
<name>Tully</name>
<age>38</age>
</record>
<record>
<id>3</id>
<age>32</age>
</record>
</data>
Output:
<table>
<tr>
<th>id</th>
<td>1</td>
<td></td>
<td>3</td>
</tr>
<tr>
<th>name</th>
<td>David</td>
<td>Tully</td>
<td></td>
</tr>
<tr>
<th>age</th>
<td></td>
<td>38</td>
<td>32</td>
</tr>
</table>