A shorter transform, illustrating a few handy techniques for this kind of thing:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="*"/>
<xsl:variable name="newline"><xsl:text>
</xsl:text></xsl:variable>
<xsl:template match="text()">
<xsl:value-of select="concat(local-name(..),' ',normalize-space(.),$newline)"/>
</xsl:template>
</xsl:stylesheet>
- strip-space says to ignore all white-space only nodes.
- You can give parameters to functions like local-name.
- When generating text output, a variable like $newline is often handy.
Optionally, adding the following transform ignores all non-leaf text nodes:
<xsl:transform match="*[*]"><xsl:apply-templates/></xsl:template>