I can't actually see how you're getting anything: your stylesheet isn't well-formed XML. Perhaps you really wrote <packet> rather than <packet>?
Please don't use disable-output-escaping until you're expert enough to know that there is no other solution. It doesn't work in all environments, and that's because it creates a nasty hidden dependency on the interface between the transformer and the serializer, which should be kept independent of each other.
I said this before: "Do try to think of XSLT as producing a result tree of nodes, not producing lexical XML with tags. " and you clearly haven't taken it on board.
In this example there's no excuse:
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><packet></xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="yes"></packet></xsl:text>
</xsl:template>
that should be
<xsl:template match="/">
<packet>
<xsl:apply-templates/>
</packet>
</xsl:template>
and this
<xsl:template match="//group">
<xsl:if test="child::node()[name()='name']">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="name"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>
<xsl:apply-templates/>
<xsl:if test="child::node()[name()='name']">
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:value-of select="name"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>
</xsl:template>
should be two separate rules:
<xsl:template match="group[name]">
<xsl:element name="{name}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="group[not(name)]">
<xsl:apply-templates/>
</xsl:template>
>i'm getting this result with some text in the middle... that shouldn't be there...
That's caused by processing the <name> element twice: once explicitly using value-of, and once implicitly when you do apply-templates to all children. Simplest solution is
<xsl:template match="name"/>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference