Although Armen's solution definitely works, I just wanted to point out that if you come across these kinds of "unflattening" problems in the future, you might want to look into grouping techniques (see
http://www.jenitennison.com/xslt/grouping or look under "Grouping" in the XSLT Programmer's Reference).
FYI -- a solution to a very similar problem was provided by Mr. Kay in the July 2002 archives under "Unflatten XML using XSLT". By slightly modifying his solution you can use:
<xsl:template match="root">
<xsl:apply-templates select="folder[@level=1]"/>
</xsl:template>
<xsl:template match="folder">
<node>
<xsl:copy-of select="@label"/>
<xsl:apply-templates select="following-sibling::*[@level=current()/@level+1][generate-id(current()) = generate-id(preceding-sibling::*[@level=current()/@level][1])]"/>
</node>
</xsl:template>
and his explanation: "What this means is: process the following siblings of this element that have an @level that is one greater than the @level of this element, provided that the most recent preceding sibling of that element at the same level as the current element is the current element.
...sam