In example 1 neither your input nor output is well-formed - you've shown an unbalanced sequence of tags. You need to understand that XSLT transforms trees into trees - the input and output therefore have to be well-formed XML.
In example 2 I suspect the rule you want to apply is that if a list-item has a list as its following sibling, you want to wrap that list inside the list-item. This is referred to as a positional grouping problem, and it's best tackled in XSLT 2.0 using the <xsl:for-each-group> instruction. Something like this:
<xsl:template match="list">
<xsl:for-each-group select="*" group-starting-with="listitem">
<listitem>
<xsl:apply-templates
select="current-group()[self::listitem]/*, current-group()[not(self::listitem)]"/>
</listitem>
</xsl:for-each-group>
</xsl:template>
You've only shown one example and I've tried to guess from that what the general rules are, but this may not be adequate for all cases.
In XSLT 1.0 this kind of thing requires explicit recursion.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference